Skip to content

Commit

Permalink
Added very simple examples used in "Getting Started"
Browse files Browse the repository at this point in the history
  • Loading branch information
jmigueprieto committed Oct 14, 2024
1 parent bfea636 commit b858441
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ public class HelloWorker implements Worker {
runnerConfigurer.init();
}
}
```
```

> **Note:** The full code for the above examples can be found [here](../examples/src/main/java/com/netflix/conductor/gettingstarted).
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.netflix.conductor.gettingstarted;

import com.netflix.conductor.sdk.workflow.def.WorkflowBuilder;
import com.netflix.conductor.sdk.workflow.def.tasks.SimpleTask;
import com.netflix.conductor.sdk.workflow.executor.WorkflowExecutor;

/**
* Very Simple Workflow As Code Example.
*
* You can use the following code to register this "hello_workflow" workflow.
*
* {
* "name": "hello_workflow",
* "description": "Hello Workflow!",
* "version": 1,
* "tasks": [
* {
* "name": "hello_task",
* "taskReferenceName": "hello_task_ref",
* "type": "SIMPLE",
* "inputParameters": {}
* }
* ],
* "inputParameters": [],
* "outputParameters": {
*
* },
* "schemaVersion": 2,
* "restartable": true,
* "workflowStatusListenerEnabled": false,
* "ownerEmail": "[email protected]",
* "timeoutPolicy": "ALERT_ONLY",
* "timeoutSeconds": 0
* }
*/
public class CreateWorkflow {

public static void main(String[] args) {
var executor = new WorkflowExecutor("http://localhost:8080/api");
var workflow = new WorkflowBuilder<Void>(executor)
.name("hello_workflow")
.version(1)
.description("Hello Workflow!")
.ownerEmail("[email protected]")
.add(new SimpleTask("hello_task", "hello_task_ref"))
.build();
workflow.registerWorkflow(true, true);
executor.shutdown();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.netflix.conductor.gettingstarted;

import com.netflix.conductor.client.automator.TaskRunnerConfigurer;
import com.netflix.conductor.client.http.ConductorClient;
import com.netflix.conductor.client.http.TaskClient;
import com.netflix.conductor.client.worker.Worker;
import com.netflix.conductor.common.metadata.tasks.Task;
import com.netflix.conductor.common.metadata.tasks.TaskResult;

import java.util.List;

public class HelloWorker implements Worker {

@Override
public TaskResult execute(Task task) {
var taskResult = new TaskResult(task);
taskResult.setStatus(TaskResult.Status.COMPLETED);
taskResult.getOutputData().put("message", "Hello World!");
return taskResult;
}

@Override
public String getTaskDefName() {
return "hello_task";
}

public static void main(String[] args) {
var client = new ConductorClient("http://localhost:8080/api");
var taskClient = new TaskClient(client);
var runnerConfigurer = new TaskRunnerConfigurer
.Builder(taskClient, List.of(new HelloWorker()))
.withThreadCount(10)
.build();
runnerConfigurer.init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.netflix.conductor.gettingstarted;

import com.netflix.conductor.client.http.ConductorClient;
import com.netflix.conductor.client.http.WorkflowClient;
import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest;

public class StartWorkflow {

public static void main(String[] args) {
var client = new ConductorClient("http://localhost:8080/api");
var workflowClient = new WorkflowClient(client);
var workflowId = workflowClient.startWorkflow(new StartWorkflowRequest()
.withName("hello_workflow")
.withVersion(1));

System.out.println("Started workflow " + workflowId);
}
}

0 comments on commit b858441

Please sign in to comment.