From a3761e09c1874e8464e4ae2a197476759d724a9a Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Thu, 5 Dec 2024 11:43:04 -0300 Subject: [PATCH 1/3] Use gradle wrapper in Run worker section --- docs/developer-guides/using-workers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/developer-guides/using-workers.md b/docs/developer-guides/using-workers.md index 12674e00..5a16a7b8 100644 --- a/docs/developer-guides/using-workers.md +++ b/docs/developer-guides/using-workers.md @@ -430,7 +430,7 @@ python3 worker.py ``` bash -gradle build run +./gradlew build run ``` From 6eac7c9385dc6ba852014759f074f2b048cb7e4e Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Thu, 5 Dec 2024 11:44:11 -0300 Subject: [PATCH 2/3] The example should be JS not TS. It should complete the task as well. --- docs/developer-guides/using-workers.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/developer-guides/using-workers.md b/docs/developer-guides/using-workers.md index 5a16a7b8..fe54e963 100644 --- a/docs/developer-guides/using-workers.md +++ b/docs/developer-guides/using-workers.md @@ -206,13 +206,17 @@ public class Workers { ``` javascript -import { ConductorWorker, Task } from "@io-orkes/conductor-javascript"; - -const worker: ConductorWorker = { +const worker = { taskDefName: "myTask", - execute: async ( - task: Task - ): Promise> => {}, + execute: async (task) => { + console.log(task) + return { + outputData: { + hello: "Hello " + task.inputData?.name, + }, + status: "COMPLETED", + }; + }, }; ``` From a39af8378fe269bab016c6650aaf83eeb90fbf86 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Thu, 5 Dec 2024 11:57:59 -0300 Subject: [PATCH 3/3] Added a Clojure and C# examples + fix other issues in code snippets. They should at least be consistent in the task name, function names that are used, etc. --- docs/developer-guides/using-workers.md | 65 ++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/docs/developer-guides/using-workers.md b/docs/developer-guides/using-workers.md index fe54e963..3dbd2308 100644 --- a/docs/developer-guides/using-workers.md +++ b/docs/developer-guides/using-workers.md @@ -224,7 +224,19 @@ const worker = { -*Coming soon.* +``` csharp +[WorkerTask(taskType: "myTask", batchSize: 5, pollIntervalMs: 500, workerId: "csharp-worker")] +public static TaskResult MyTask(Conductor.Client.Models.Task task) +{ + var inputData = task.InputData; + var result = task.ToTaskResult(); + result.OutputData = new Dictionary + { + ["message"] = "Hello " + inputData.GetValueOrDefault("name", null) + }; + return result; +} +``` @@ -248,7 +260,14 @@ func myTask(task *model.Task) (interface{}, error) { -*Coming soon.* +``` clojure +(def worker + {:name "myTask", + :execute (fn [d] + (let [name (get-in d [:inputData :name])] + {:status "COMPLETED" + :outputData {"message" (str "hello " name)}}))}) +``` @@ -281,11 +300,16 @@ Full worker example: [https://github.com/conductor-oss/python-worker-container/t Run the annotated Java worker using WorkflowExecutor. ``` java -WorkflowExecutor executor = new WorkflowExecutor("http://server/api/"); -//List of packages (comma separated) to scan for annotated workers. +var client = ApiClient.builder() + .basePath("https://developer.orkescloud.com/api") + .credentials("_CHANGE_ME_", "_CHANGE_ME_") + .build(); +int pollingInterval = 50; +var executor = new WorkflowExecutor(client, pollingInterval); +// List of packages (comma separated) to scan for annotated workers. // Please note, the worker method MUST be public and the class in which they are defined -//MUST have a no-args constructor -executor.initWorkers("com.company.package1,com.company.package2"); +// MUST have a no-args constructor +executor.initWorkers("io.orkes.conductor.examples.workers"); ``` @@ -314,7 +338,19 @@ orkesConductorClient({ -*Coming soon.* + ``` csharp +ApiExtensions.Configuration = new Configuration +{ + BasePath = "https://developer.orkescloud.com/api", + AuthenticationSettings = new OrkesAuthenticationSettings("_CHANGE_ME_", "_CHANGE_ME_") +}; + +var host = WorkflowTaskHost.CreateWorkerHost( + ApiExtensions.Configuration, + LogLevel.Information +); +host.Start(); + ``` @@ -337,18 +373,27 @@ apiClient := client.NewAPIClient( SECRET, ), settings.NewHttpSettings( - "https://play.orkes.io/api", + "https://developer.orkescloud.com/api", )) taskRunner = worker.NewTaskRunnerWithApiClient(apiClient) -taskRunner.StartWorker("simple_task", examples.SimpleWorker, 1, time.Second*1) +taskRunner.StartWorker("myTask", myTask, 1, time.Second*1) ``` -*Coming soon.* +``` clojure +(defn -main + [& args] + ;; Create and run the task executor + (tr/runner-executer-for-workers options [worker]) + ;; Keep the process running + (loop [] + (Thread/sleep 1000) + (recur))) +```