How do I restart workflow from specific point programmatically?

Let’s say I have such a workflow as:

workflowProps = props
    val extension = try {
      validationStage(order, participant.omsId, omsOrderId)
    } catch (e: ApplicationFailure) {
      null
    }

    if (extension != null) {
      emitCodes(order, participant, deviceId, omsOrderId)

      if (order is MilkOrder && order.paymentType == "1") Workflow.await { orderToClose }
      else Workflow.await(Duration.ofDays(getDayCount(extension))) { orderToClose }

      val remUrl = registrarActivity.getRemUrl()
      remActivity.sendAnnulmentReport(participant, remUrl, deviceId, extension, omsOrderId)
      orderActivity.closeOrderWithBuffers(omsOrderId, orderToClose)
    }

    Workflow.sleep(workflowProps.closeToDeleteDelay)
    orderActivity.deleteOrderWithBuffers(omsOrderId)

Whenever it fails with non-retryable error, I want to restart it but from a specific point (last 2 lines of code)

    Workflow.sleep(workflowProps.closeToDeleteDelay)
    orderActivity.deleteOrderWithBuffers(omsOrderId)

Is there a way to accomplish this? Thanks in advance!

I think what you are describing is the reset feature. You can reset completed workflow executions to specific WorkflowTaskStarted event via tctl (tctl workflow reset)
or via SDK, sample here. Note that reset is going to start a new execution (with same workflow id, different run id) and replay history against your workflow code to the specified reset point and then continue execution.

Imo you could maybe accomplish the same thing via business logic and error handling in your workflow rather than relying on failing your workflows. Not sure where you are throwing the non-retryable error in your code, if you can share.

1 Like