I have a scenario where my workflow consists of 4 activity calls (A,B,C,D) where A is sync while other three are async calls. I want the client to get the sync response of A immediately while the rest three activities can run in background.
Is there any way to achieve this? As per my understanding, if a workflow returns a response, it gets marked as completed even when the rest of the activities are still in scheduled/running state.
My requirement is to return the sync response of A, but rest of the activities should be executed and then only workflow to be marked as completed.
@maxim Thanks for the response.
Followup queries :
To compensate Activity A call, that needs to be handled in child workflow definition as part of failure handling? Because the parent workflow must have got completed, so there would be no point in defining the compensation in parent workflow. Is my understanding correct?
How can we get the response being returned from the activity being executed as part of compensating SAGA transaction ?
Does the SAGA compensating transaction get logged in workflow execution history?
Yes, you would do the compensation in the child workflow (if any of B,C,D fail as you mentioned)
One way you could do it is have the parent return the WorkflowExecution of the async child back to the client, see the async child sample, specifically: samples-java/Starter.java at main · temporalio/samples-java · GitHub
With that, you can reconnect to the child workflow in the client code and wait for its results (or query it if you want) via:
// connect to the async child wf execution after parent returned
WorkflowStub childStub =
client.newUntypedWorkflowStub(
childWorkflowExecution.getWorkflowId(),
Optional.of(childWorkflowExecution.getRunId()),
Optional.empty());
// wait for the child workflow to complete
String childResult = childStub.getResult(String.class); // you can use childStub.query(...) to query as well
Yes, if your compensation defines invocations of child workflows or activities, they will be recorded in history.
Thanks @tihomir for the explanation.
But point 2, let me clarify my question. If any activity call is being made, using saga.compensate() function, is there any way to fetch the result of that activity call. Because the compensate() call returns void, so trying to understand that.
saga.compensate() triggers compensation which can include multiple activity invocations.
You can get results of each in saga.addCompensation, for example: