Implementing Dynamic Approval flow using temporal

Hello All,

I am trying to implement a Order Approval workflow using temporal.

I have a external service which tells who is the next approver.
I am trying to understand about running set of steps in an order repeatedly until the external service says there are no more approvers and then i end the workflow.

Sequence of steps:

  1. WF-> Api1
  2. If Api1 says has approvers, then send notification to approver.
  3. If no approvers, then mark order as approved and exit the workflow.
  4. When approver present, Wait until the approver approves.
  5. If approver did not respond in x days, then send notification and wait.
  6. Once Approver approves, then repeat from step 1.

I was thinking to have a while loop in the parent workflow, until the child workflow return success.
child workflow will have all the business logic.
In child workflow i want to use signals for waiting on approver.

Please suggest me if the above solution works. If not please provide a solution which could work for me using temporal.

Thanks,
Dilip

Yes, your solution works. Child workflow is not required in your case, but it is OK to use it.

Can you confirm the below Sudo design works
Work Flow contains
While Loop{
-Activity1: Getting the current pending approver
-If Approver present:
-Activity2: Send Notifications.
-If No Approver:
-Exit WorkFlow.
-Wait on Signal
-If Signal Received
- Continue While Loop.

I have few questions here:

  1. Does Signal have timeout.
  2. How can i make sure if i do not receive confirmation from signal in specific period i want to perfom some other action?

Thanks,
Dilip

  1. Does Signal have timeout.

Signals don’t have timeouts they are always delivered to the corresponding channel.

    1. How can i make sure if i do not receive confirmation from signal in specific period i want to perfom some other action?

The simplest is to use Channel.ReceiveWithTimeout or workflow.AwaitWithTimeout. For more complex use cases use Selector to listen on multiple Channels and Futures.

Can my workflow have all activities under while loop. Is it going to be problem?

Can i have while loop surrounding the workflow.AwaitWithTimeout(timeout,result_of_signal) and perform some operation if await is timedout and again wait on same signal?

When timeout happens, is signal lost or need to create new signal?

If temporal workflow is stopped and restarted, can it recreate the signal with same name?

This is code. So you can do whatever you want. Loops are permitted. Waiting on signals can be done multiple times.

When timeout happens, is signal lost or need to create new signal?

Nothing is ever lost unless your code decides to drop something.

If temporal workflow is stopped and restarted, can it recreate the signal with same name?

Temporal doesn’t have the notion of “stopping workflow”. Workflow can complete/fail, be canceled, timed out, or terminated. What is the problem you are trying to solve here?