From 7a4ab58d5a8c07c929a01f7dd607e16bf31e79d8 Mon Sep 17 00:00:00 2001 From: RizaFarheen Date: Mon, 20 Mar 2023 15:13:34 +0400 Subject: [PATCH] Create simple-task.md --- docs/operators/simple-task.md | 159 ++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 docs/operators/simple-task.md diff --git a/docs/operators/simple-task.md b/docs/operators/simple-task.md new file mode 100644 index 00000000..923ef7ff --- /dev/null +++ b/docs/operators/simple-task.md @@ -0,0 +1,159 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Worker Task (Simple Task) + +```json +"type" : "SIMPLE" +``` + +A Simple task is a Worker task that requires an external worker for polling. The Workers can be implemented in any language, and the Conductor provides additional features such as metrics, server communication, and polling threads that make the worker creation process easier. + +## Configurations​ + +```json +{ + "name": "workflow_name", + "description": "Edit or extend this sample workflow. Set the workflow name to get started", + "version": 1, + "tasks": [ + { + "name": "task_name", + "taskReferenceName": "task_name_ref", + "inputParameters": {}, + "type": "SIMPLE" + } + ] +} + +``` + +## Examples + + + + +```json +{ + "name": "workflow_name", + "description": "Edit or extend this sample workflow. Set the workflow name to get started", + "version": 1, + "tasks": [ + { + "name": "task_name", + "taskReferenceName": "task_name_ref", + "inputParameters": {}, + "type": "SIMPLE" + } + ] +} +``` + + +This is a banana 🍌 + + + This is a banana 🍌 + + + This is a banana 🍌 + + + This is a banana 🍌 + + + This is a banana 🍌 + + + This is a banana 🍌 + + + +
Sample Workflow Implementation with Java Worker +

+Let’s see a sample workflow definition: + +```json +{ + "name": "workflow_name", + "description": "Edit or extend this sample workflow. Set the workflow name to get started", + "version": 1, + "tasks": [ + { + "name": "task_name", + "taskReferenceName": "task_name_ref", + "inputParameters": {}, + "type": "SIMPLE" + } + ], + "schemaVersion": 2, + "ownerEmail": "riza.farheen@orkes.io" +} +``` + +Once the workflow is set, you must set up the worker to poll the worker. +
+ +**Setting Up a Sample Worker** + +Suppose the worker is to be set up in Java; you need to clone the [Orkesworkers Java](https://github.com/orkes-io/orkesworkers) repo in the IDE of your choice. +:::note Best Practice +As a best practice, under the [workers’](https://github.com/orkes-io/orkesworkers/tree/main/src/main/java/io/orkes/samples/workers) folder, you can keep only the **SimpleWorker.java** file and trash the rest for an error-free running of the application. +::: + +The code for the [SimpleWorker](https://github.com/orkes-io/orkesworkers/blob/main/src/main/java/io/orkes/samples/workers/SimpleWorker.java) looks like this: + +```java +package io.orkes.samples.workers; + +import com.netflix.conductor.client.worker.Worker; +import com.netflix.conductor.common.metadata.tasks.Task; +import com.netflix.conductor.common.metadata.tasks.TaskResult; +import org.springframework.stereotype.Component; + +@Component +public class SimpleWorker implements Worker { + + @Override + public String getTaskDefName() { + return "simple_worker"; + } + + @Override + public TaskResult execute(Task task) { + TaskResult result = new TaskResult(task); + result.setStatus(TaskResult.Status.COMPLETED); + return result; + } +} +``` + +In this section, you must replace “simple_worker” with the task name you created. Here, it would be “task_name”. + +```java +@Override + public String getTaskDefName() { + return "task_name"; + } +``` + +* Next, you need to create an application in your Conductor server and provide the authentication details. If you take the [Playground](https://play.orkes.io/) as an example, you can [create an application](https://orkes.io/content/docs/getting-started/concepts/access-control-applications#configuring-application) and [generate the access keys](https://orkes.io/content/docs/getting-started/concepts/access-control-applications#access-keys). +* Ensure to [provide access](https://orkes.io/content/docs/getting-started/concepts/access-control-applications#workflow--task-permissions) to the task & workflows while creating the application. +* Under the **application.properties** in your worker, replace the key ID and secret with that of the copied values from the Playground. + +```json +conductor.server.url=https://play.orkes.io/api/ +conductor.security.client.key-id=_CHANGE_ME_ +conductor.security.client.secret=_CHANGE_ME_ +``` + +This is how you wire your tasks to the worker. The next step is to run the workflow and the Java application. + +**Run Worker** + +You can either use the following command or run the worker through your IDE. + +```./gradlew run``` + +

+
\ No newline at end of file