How to wait for an incoming hook

Imagine I have the following workflow

workflow --> executeActivity1 (call an external service, pass executation id)
                 --> awaitForIncomingHook (external service would invoke your application back at a later stage)
                 --> doMoreStuff

One of the activity is to call another service. This service is async and can be completed at a far time future (maybe minutes, but maybe days). This service supports making a call back to a given URL whenever it is completed.

So I want to call this service, set the execution id, and then wait for this service to call me back before I continue with the rest of the workflow.

What is the best approach here? Is it best to do a Workflow.await and a Signal, where I have some API layer that posts a Signal to the workflow whenever it gets a call back?

Hi @ktalebian,

typically you have two options either using signal to report completion of your external service as you mentioned or using async activity completion (see sample here) .

In the case where your external service can heartbeat (continuously report progress via ActivityCompletionClient or some callback) using async activity completion would be fine.
Otherwise having an activity to enqueue the external service and then having a signal for the reply is preferred.

@tihomir thanks for the reply.

I’m not sure I understand the async activity completion way. How would the ActivityCompletionClient be invoked via the external service? There would basically be an API service that the external service calls. This API service would then have to somehow send a Signal to the Workflow to continue with the next execution. Are you suggesting the API service would somehow send something to the Activity?

How would the ActivityCompletionClient be invoked via the external service?

Typically you would need to pass the activity task token to your external service (as part of lets say a rest call) and the external service would use Temporal client apis to create an activity completion client and either heartbeat or complete the activity based on the passed task token.

For your use case (and if you do not control this 3rd party service) I think having an activity to enqueue it and waiting for its completion via signal would be preferred.