Replaying the workflow based on certain condition

Hi Maxim, trying to replay a workflow based on certain condition, but did not found a better way to do that could you please help with this.

Hi @Manish_Baraskar

Workflows are replayed by temporal SDK under certain conditions, e.i If a Worker crashes the work will be placed in a new Worker (if available) and the SDK replays the event history, to restore the workflow state, to continue with the execution of any pending work.

For test/debug purposes you can use the WorkflowReplayer utility. See an example in java here

Do you mean reset?

Can you explain a little bit about your use case?

Just to add, if you mean “reset”, from a running execution you can use continueasNew as same workflow type, for example:

Workflow.continueAsNew(...);

or as a different wf type:

Workflow.continueAsNew("workflowType", ...);

based on some conditions in your workflow code.

Another options could be reset feature (via “tctl wf reset” command, or ResetWorkflowExecution api) to reset to a specific event in history (WorkflowTaskScheduled/Started events). Reset is going to create a new execution and replay history up to the defined reset event and then continue. If the exec you are resetting is running, it will be terminated first and a new exec created.

Hi @antonio.perez,

My use case is like after getting some data either success/failed from a system, I will unblock my workflow with signal. After that let say a failed response is received I have to re-execute the same set of activities to again fetch the response from the system, basically I have to replay that particular scenario.

For Ex - If I had sent a request to bank for processing my payment, in response bank has sent me some data but with failure status means for some reason payment failed so in that case I again want to re-initiate my payment means again sending request to bank and again waiting for their response against that payment.

The main rule of Temporal is to not think about replay when writing business logic. Think about workflow as a function that keeps running in the presence of failure.

The way to solve your problem is to repeat the function that implements the payment and waits for bank response. You can use a standard loop in the language of your choice for this. Something like:

while(!paymentSuccessful) {
   requestPaymentProcessing(...);
   paymentSuccessful = waitForBankResponse(...);
}