Tuomas Toivonen
Tuomas Toivonen

Reputation: 23492

What is BPMN User Task equivalent in temporal.io and how to implement it?

I'm evaluating temporal.io as an modern workflow-as-code alternative for BPMN based solutions such as Camunda.

In my scenario workflow orchestrates activity workers, which calls external microservices for business transactions. Business transactions may encounter business exceptions or require human action to proceed the flow, and rises required user tasks. Workflow should block at certain points until there are no blocking tasks for that specific activity.

Should the blocking task logic reside inside activities and services, keeping the workflow definition more abstract and deterministic? I premuse an activity should simply throw an runtime exception when there is a blocking task, is that right? Then, how do I continue the workflow when the task is completed?

Or should I use workflow signals to mimic BPMN user tasks and if so, how do I send a signal from an external service to a specific workflow instance?

Upvotes: 3

Views: 1453

Answers (2)

Václav Brož
Václav Brož

Reputation: 11

You should use an asynchronous way how to obtain information that user performed a task. This should be done inside a Workflow, not an Activity. The common pattern is inside the workflow (since you're referring to Camunda, I'd expect you working in Java):

Workflow.await(()->userTaskDoneFlag==true)

And the you may declare a signal method that will modify the flag:

@SignalMethod
void onUserTaskDone();

With the following implementation:

@Override
void onUserTasakDone() {
  userTaskDoneFlag=true;
}

And then in the microservice that is responsible to record the user task result (e.g. some frontend app with node.js), you can call the workflow signal method. The workflow will continue from the line with await.

There is also a possibility to specify a timeout.

You can also launch a child workflow for the user input task that will allow you isolate business logic related to the user task but again the asynchronous waiting should be inside a workflow, not an activity.

Upvotes: 1

Tihomir Surdilovic
Tihomir Surdilovic

Reputation: 106

Probably easiest way is to have an activity that notifies your external system responsible for interacting with human actors, and then use signals to notify workflow of the completion of the human decision. With Temporal you can write workflow code that waits for multiple signals in case there are multiple actors/decisions involved.

Other options could be to store a list of tasks in an external system and notify your workflow from that system directly (again via signals), or could have a workflow per "approver" which can hold a list of assigned tasks inside these workflows that you could query state, or could have them send notifications when all tasks have been performed.

how do I send a signal from an external service to a specific workflow instance?

You would use Temporal SDK client api to send a signal to a workflow execution thats uniquely identified via namespace name, task queue name workflow id. Not sure which programming language you are using but maybe this Go sample can help.

Upvotes: 3

Related Questions