javatemporal-workflow

Fire and forget activity in temporal


I have an activity method which I want to run in async. I tried using Async. procedure method to run the activity async but since this was the last statement of the workflow, it got scheduled but did not get picked. Is there any way to wait for the activity to get picked?

Here is the example code

private final MyActivity myActivity = Workflow.newActivityStub(MyActivity.class, activityOptions);
@Override
public SomeObject execute(Payload payload){
    SomeObject someObject = myActivity.methodA(payload);

    // Calling some more activities here based on the result of someObject

    Async.procedure(myActivity::methodB, payload);
    return someObject;
}

Since

Async.procedure(myActivity::methodB, payload);

is just before return statement, its get scheduled but did not start execution as workflow has ended.


Solution

  • You can either wait for the Activity to complete before ending the Workflow or start a Child Workflow with Parent Close Policy = Abandon that runs the Activity (and waits for its completion).