Hi Temporal,
We had such requirement:
Context: we have an activity A send a request to external service.
And this external service will return the response, and a signal will be sent back to the workflow.
Requirement:
If signal not received with in 5 seconds, then that particular activity A should be retried, and maximum retry count should not go beyond 3.
So, for above retry requirement I have developed some code, it could achieve the goal but not sure if this “do while” loop, construction of mutableSideEffect and updateRequestId are the right approaches or any other corner cases missing. Please help to have a look! Thank you!
Pseudo code:
requestId has a field for attemptCount using Workflow.mutableSideEffect to construct.
Workflow:
activityA.initiateScan() → send a request to external system.
signalTimeout → Duration of 5 seconds;
checkReattemptCount → if requestId.getAttemptCount() < 3;
workflowWaitForResult → !Workflow.await(signalTimeout, this::isSignalResultReceived);
isSignalResultReceived → check if signal received
updateRequestId → requestId.setAttemptCount(++attemptCount);
…
do {
updateRequestId(requestId);
activityA.initiateScan();
} while (workflowWaitForResult() && checkReattemptCount(requestId));
…
Best regards,
Jx