From d94115741d9ad81adc2061422b1eabf58bcdaa7b Mon Sep 17 00:00:00 2001 From: Matthew Avery Date: Thu, 8 Aug 2024 16:20:39 -0400 Subject: [PATCH] Add beans and deserializers to @WorkerTask methods. --- .../sdk/workflow/executor/WorkflowExecutor.java | 9 +++++++++ .../sdk/workflow/executor/task/AnnotatedWorker.java | 5 +++++ .../executor/task/AnnotatedWorkerExecutor.java | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/WorkflowExecutor.java b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/WorkflowExecutor.java index 15ba64683..d80d55928 100644 --- a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/WorkflowExecutor.java +++ b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/WorkflowExecutor.java @@ -36,6 +36,7 @@ import com.netflix.conductor.sdk.workflow.utils.ObjectMapperProvider; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; import com.sun.jersey.api.client.ClientHandler; import com.sun.jersey.api.client.config.DefaultClientConfig; @@ -241,4 +242,12 @@ public TaskClient getTaskClient() { public WorkflowClient getWorkflowClient() { return workflowClient; } + + public void addBean(Object bean) { + annotatedWorkerExecutor.addBean(bean); + } + + public void registerModule(Module module) { + annotatedWorkerExecutor.registerModule(module); + } } diff --git a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorker.java b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorker.java index 51b8abcff..57a3a8241 100644 --- a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorker.java +++ b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorker.java @@ -27,6 +27,7 @@ import com.netflix.conductor.sdk.workflow.utils.ObjectMapperProvider; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.Module; import com.fasterxml.jackson.databind.ObjectMapper; public class AnnotatedWorker implements Worker { @@ -51,6 +52,10 @@ public AnnotatedWorker(String name, Method workerMethod, Object obj) { om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } + void registerModule(Module module) { + om.registerModule(module); + } + @Override public String getTaskDefName() { return name; diff --git a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorkerExecutor.java b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorkerExecutor.java index 56c06003b..fe237f867 100644 --- a/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorkerExecutor.java +++ b/java-sdk/src/main/java/com/netflix/conductor/sdk/workflow/executor/task/AnnotatedWorkerExecutor.java @@ -23,6 +23,7 @@ import com.netflix.conductor.client.worker.Worker; import com.netflix.conductor.sdk.workflow.task.WorkerTask; +import com.fasterxml.jackson.databind.Module; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import com.google.common.reflect.ClassPath; @@ -51,6 +52,8 @@ public class AnnotatedWorkerExecutor { private WorkerConfiguration workerConfiguration; + private Set modules = new HashSet<>(); + public AnnotatedWorkerExecutor(TaskClient taskClient) { this.taskClient = taskClient; this.workerConfiguration = new WorkerConfiguration(); @@ -189,6 +192,9 @@ public void startPolling() { (taskName, method) -> { Object obj = workerClassObjs.get(taskName); AnnotatedWorker executor = new AnnotatedWorker(taskName, method, obj); + for (Module module : modules) { + executor.registerModule(module); + } executor.setPollingInterval(workerToPollingInterval.get(taskName)); executors.add(executor); }); @@ -218,4 +224,8 @@ List getExecutors() { TaskRunnerConfigurer getTaskRunner() { return taskRunner; } + + public void registerModule(Module module) { + modules.add(module); + } }