I have a workflow which sends an http requests via an activity and then waits for another http request which acts as a response of first request.
I am achieving this with signal. (the body of second http request is sent as a signal parameter to the workflow).
workflow awaits the response for n seconds and if response is not received in given time then workflow should restart immediately. I am achieving this with Retryable failure. (if signal is not received in time code throws retryable exception).
and if signal is received in time then workflow should restart after m minutes. Keeping the event history limit of 50k in mind i am using continueAsNew
to start new instance after m minutes of sleep.
The issue i am facing is that the continueAsNew
does not inherit retry policy of current workflow and thus after 1st successful run new workflow does not retry on failure of not receiving the response.
I’ve considered child workflows as an option too but eventually parent workflows event history will be reached anyways and also considering the overhead of invoking child workflows I am trying to avoid that option unless there is no other way.
I could also do continue as new instead of throwing a retryable exception but that will affect the visibility of status as both success and failure cases will show up as continuedAsNew
, and that will also be an overuse of continueAsNew which I would like to avoid as it is not recommended.
Workflow failures are not recommended, but since the use case spans over multiple activities i don’t think i can use activity retry policies thus relying on workflow retry policies.
- Keeping above points in consideration, I would like to know what will be the best approach to achieve this use case.
- Also need confirmation on whether not inheriting retry policy is a conscious design decision or it could be a bug.
sdk version: 1.13.0
public void workflowMethod() {
activity.sendRequest();//first outgoing httpReqest sent
await(ofSeconds(n), () -> response != null);
if (response == null) {
throw ApplicationFailure.newFailure("Response not received in time", RuntimeException.class.getTypeName(), null);
}
activity.onResponseReceived(response);
Workflow.sleep(ofMinutes(m));
Workflow.continueAsNew();
}
@Override
public void onResponseReceived(Object response) {//body of second incoming http request
log.info("response received.");
this.response = response;
}