From 523597ba2240427ad0c94908fee38c990c800ca5 Mon Sep 17 00:00:00 2001 From: Abhishek Gupta Date: Wed, 5 Jul 2023 09:48:13 -0400 Subject: [PATCH 1/2] Added task domain snippets for JAVA SDK --- docs/developer-guides/task-to-domain.md | 58 ++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/docs/developer-guides/task-to-domain.md b/docs/developer-guides/task-to-domain.md index b613f9d7..0be7d26d 100644 --- a/docs/developer-guides/task-to-domain.md +++ b/docs/developer-guides/task-to-domain.md @@ -56,15 +56,69 @@ Let's configure the workers with a domain label called `test`. Every worker poll | Annotation `@WorkerTask` constructor param | `domain` | `@WorkerTask(value="taskName", domain="test")` | Code example for `TaskRunner`: -```java dynamic https://github.com/orkes-io/orkes-conductor-client/blob/main/example/java/io/orkes/conductor/sdk/examples/TaskDomainWorker.java#L111-L153 section=1 ../examples/TaskDomainWorker.java +```java +private static void startTaskRunnerWorkers(TaskClient taskClient) { + List workers = Arrays.asList(new TaskWorker()); + TaskRunnerConfigurer.Builder builder = new TaskRunnerConfigurer.Builder(taskClient, workers); + + Map taskToDomains = new HashMap<>(); + taskToDomains.put("task-domain-runner-simple-task", "test"); + Map taskThreadCount = new HashMap<>(); + + TaskRunnerConfigurer taskRunner = + builder.withThreadCount(2) + .withTaskToDomain(taskToDomains) + .withTaskThreadCount(taskThreadCount) + .withSleepWhenRetry(500) + .withWorkerNamePrefix("task-domain") + .withUpdateRetryCount(3) + .build(); + + // Start Polling for tasks and execute them + taskRunner.init(); + + // Optionally, use the shutdown method to stop polling + taskRunner.shutdown(); + } + +private static class TaskWorker implements Worker { + + @Override + public String getTaskDefName() { + return "task-domain-runner-simple-task"; + } + + public TaskResult execute(Task task) { + TaskResult result = new TaskResult(task); + + result.getOutputData().put("key2", "value2"); + result.getOutputData().put("amount", 145); + result.setStatus(TaskResult.Status.COMPLETED); + + return result; + } +} ```

Code example for `@WorkerTask`: -```java dynamic https://github.com/orkes-io/orkes-conductor-client/blob/main/example/java/io/orkes/conductor/sdk/examples/TaskDomainWorker.java#L98-L109 section=3 ../examples/TaskDomainWorker.java +```java +@WorkerTask(value="task-domain-annotated-simple-task", domain="test") +public TaskResult sendAnnotatedTaskDomain(Task task) { + TaskResult result = new TaskResult(task); + + result.getOutputData().put("key", "value"); + result.getOutputData().put("amount", 123.45); + result.setStatus(TaskResult.Status.COMPLETED); + + return result; +} + ``` +View the [complete code here](https://github.com/orkes-io/orkes-conductor-client/blob/main/example/java/io/orkes/conductor/sdk/examples/TaskDomainWorker.java). + From 66d39b435f66098678d7b452b867ff051b75f463 Mon Sep 17 00:00:00 2001 From: Abhishek Gupta Date: Wed, 5 Jul 2023 09:50:37 -0400 Subject: [PATCH 2/2] Fixed indentation --- docs/developer-guides/task-to-domain.md | 44 ++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/developer-guides/task-to-domain.md b/docs/developer-guides/task-to-domain.md index 0be7d26d..9836a1c5 100644 --- a/docs/developer-guides/task-to-domain.md +++ b/docs/developer-guides/task-to-domain.md @@ -58,28 +58,28 @@ Let's configure the workers with a domain label called `test`. Every worker poll Code example for `TaskRunner`: ```java private static void startTaskRunnerWorkers(TaskClient taskClient) { - List workers = Arrays.asList(new TaskWorker()); - TaskRunnerConfigurer.Builder builder = new TaskRunnerConfigurer.Builder(taskClient, workers); - - Map taskToDomains = new HashMap<>(); - taskToDomains.put("task-domain-runner-simple-task", "test"); - Map taskThreadCount = new HashMap<>(); - - TaskRunnerConfigurer taskRunner = - builder.withThreadCount(2) - .withTaskToDomain(taskToDomains) - .withTaskThreadCount(taskThreadCount) - .withSleepWhenRetry(500) - .withWorkerNamePrefix("task-domain") - .withUpdateRetryCount(3) - .build(); - - // Start Polling for tasks and execute them - taskRunner.init(); - - // Optionally, use the shutdown method to stop polling - taskRunner.shutdown(); - } + List workers = Arrays.asList(new TaskWorker()); + TaskRunnerConfigurer.Builder builder = new TaskRunnerConfigurer.Builder(taskClient, workers); + + Map taskToDomains = new HashMap<>(); + taskToDomains.put("task-domain-runner-simple-task", "test"); + Map taskThreadCount = new HashMap<>(); + + TaskRunnerConfigurer taskRunner = + builder.withThreadCount(2) + .withTaskToDomain(taskToDomains) + .withTaskThreadCount(taskThreadCount) + .withSleepWhenRetry(500) + .withWorkerNamePrefix("task-domain") + .withUpdateRetryCount(3) + .build(); + + // Start Polling for tasks and execute them + taskRunner.init(); + + // Optionally, use the shutdown method to stop polling + taskRunner.shutdown(); +} private static class TaskWorker implements Worker {