Sequential long-running activities

Hello, community!

I have a workflow that runs two activities. The first activity makes several asynchronous service calls, each of which is long-running. The second activity should not be run until each of the service calls in the first activity are complete.

I could block on the first activity and wait until it’s done before calling the second, but this seems prone to problems (e.g., an activity worker dies, etc.) I’ve looked at the HelloAsyncActivityCompletion example, but I’m not sure if that approach would apply here, and if it would, how to extend it to the case of two (or more) activities. I’d greatly appreciate any insights on how to do this.

Thanks!

1 Like

Can the asynchronous calls when completed invoke Temporal APIs?
The recommended approach is to invoke these async APIs from activities and then let them report their completion through signals.

The ideal solution would be hosting activities in those remote services. This way workflow would just invoke them.

Thanks @maxim

In this case, my first activity launches several (GCP) dataflows and returns a set of result objects whose state can be queried. Something like this:

// Implements a @WorkflowMethod
public boolean workflowMethod(Request someRequest) {
Set results = activities.launchDataflows(someRequest);
// best practice for waiting?
activities.doSomethingAfterDataflowsFinish();
}

Each DataflowResult has a synchronous waitUntilFinish method. One can also call getState and compare against the success state. I could instrument a periodic check on the result states (say, with a backoff) either directly in the workflow method, or in a new activity, or…?

I’m mostly asking about best practices (I’m quite new to Temporal) and want to take proper advantage of Temporal’s robustness in the event of failures.

1 Like

I would recommend breaking this into two separate activities. One to initiate the dataflow and another to wait for its state changes. The waiting activity should poll on the getState periodically and heartbeat back to Temporal to ensure that it is retried if its worker goes down.

2 Likes

Thanks so much for sharing the recommendation, Maxim. Have a great weekend!

1 Like