# Replaying the workflow based on certain condition

**URL:** <https://community.temporal.io/t/replaying-the-workflow-based-on-certain-condition/6502>\
**Category:** Community Support\
**Created:** [November 16, 2022, 12:16pm UTC](https://community.temporal.io/t/replaying-the-workflow-based-on-certain-condition/6502 "2022-11-16T12:16:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manish\_Baraskar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/manish_baraskar/32/3004_2.png) [@Manish\_Baraskar](https://community.temporal.io/u/Manish_Baraskar)\
**Post date:** [November 16, 2022, 12:16pm UTC](https://community.temporal.io/t/replaying-the-workflow-based-on-certain-condition/6502/1 "2022-11-16T12:16:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [November 16, 2022, 1:31pm UTC](https://community.temporal.io/t/replaying-the-workflow-based-on-certain-condition/6502/2 "2022-11-16T13:31:37Z")

</div>

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](https://github.com/temporalio/samples-java/blob/main/src/test/java/io/temporal/samples/hello/HelloActivityReplayTest.java)

Do you mean [reset](https://docs.temporal.io/tctl-next/workflow#reset)?

Can you explain a little bit about your use case?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 16, 2022, 1:48pm UTC](https://community.temporal.io/t/replaying-the-workflow-based-on-certain-condition/6502/3 "2022-11-16T13:48:36Z")

</div>

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](https://github.com/temporalio/api/blob/master/temporal/api/workflowservice/v1/service.proto#L250) 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.

---

<div class="post-metadata">

**Author:** ![Manish\_Baraskar](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/manish_baraskar/32/3004_2.png) [@Manish\_Baraskar](https://community.temporal.io/u/Manish_Baraskar)\
**Post date:** [November 16, 2022, 2:19pm UTC](https://community.temporal.io/t/replaying-the-workflow-based-on-certain-condition/6502/4 "2022-11-16T14:19:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [November 16, 2022, 4:52pm UTC](https://community.temporal.io/t/replaying-the-workflow-based-on-certain-condition/6502/5 "2022-11-16T16:52:32Z")

</div>

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:

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

```
