Skip to content

Commit

Permalink
Merge pull request #234 from avery1701/workertask_deserialization_config
Browse files Browse the repository at this point in the history
Add beans and deserializers to @WorkerTask methods.
  • Loading branch information
v1r3n authored Aug 17, 2024
2 parents 950783f + d941157 commit 87d8dd3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +52,8 @@ public class AnnotatedWorkerExecutor {

private WorkerConfiguration workerConfiguration;

private Set<Module> modules = new HashSet<>();

public AnnotatedWorkerExecutor(TaskClient taskClient) {
this.taskClient = taskClient;
this.workerConfiguration = new WorkerConfiguration();
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -218,4 +224,8 @@ List<Worker> getExecutors() {
TaskRunnerConfigurer getTaskRunner() {
return taskRunner;
}

public void registerModule(Module module) {
modules.add(module);
}
}

0 comments on commit 87d8dd3

Please sign in to comment.