public static class SampleWorkflowImpl implements SampleWorkflow {
private final ActivityStub activities =
Workflow.newUntypedActivityStub(
ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(30)).build());
@Override
public String sampleMethod() {
EncodedValues encodedValues = new EncodedValues("val1", "val2");
return (String) activities.execute("Execute", Object.class, encodedValues);
}
}
static class TestDynamicActivityImpl implements DynamicActivity {
@Override
public Object execute(EncodedValues args) {
System.out.println("execute");
return "dynamic activity executed";
}
}
Here I directly implemented the DynamicActivity interface, overridden the execute method. And created stub using Workflow.newUntypedActivityStub and called the execute method activities.execute("Execute", Object.class, encodedValues);
Here you are passing activityName as ActivityType1, How it is executing the execute method? we should pass it as Execute, right? I tried but it is working.
@ActivityInterface
public interface TemporalTask{
Object executeTask(Object obj);
}
Our framework just has this interface alone.
User needs to implement their task needs to be completed.
Like this,
public class Task1 implements TemporalTask{
@Override
Object executeTask(Object obj){
....
....
}
}
public class Task2 implements TemporalTask{
@Override
Object executeTask(Object obj){
....
....
}
}
I will be having a workflow code that will receive a list of TemporalTask objects as input, and it will iterate all the TemporalTask from the list and execute its task by calling exeuteTask method.
I have a flag to differentiate whether this needs to be called in sequential or parallel.
Here each task will have its own timeout properties and retry options
I am trying to achieve this.
Kindly let me know you need any clarifications. Thanks in advance!!
private final TaskExecutor taskExecutor =
Workflow.newActivityStub(
TaskExecutor.class,
ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(40)).build());
...
Object result = taskExecutor.executeTask(taskName, input);
Note that the above code is not going to work out of the box as the default DataConverter doesn’t support deserialization of arguments of polymorphic types. So you either need to implement the custom DataConverter that works with Java polymorphism or use concrete types in the activity signature.
I’m trying to get my head around Dynamic Activity - and I’ve seen the examples etc - but I still am unsure as to what significance the activityName has - can you please confirm?