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.

@tihomir

In the case where your external service can heartbeat (continuously report progress via ActivityCompletionClient or some callback) using async activity completion would be fine.

Does the external service have to heartbeat in order for async activity completion to work? Or was the concern about the activity dragging too long if the external service fails and never completes the activity (in which case the activity start-to-close timeout could help)?

Typically you would need to pass the activity task token to your external service (as part of lets say a rest call)

Any suggestion on how to pass this activity task token? From a quick try the token seems larger than 100 bytes and doesn’t look like something one would pass as query parameter in a REST call, for example. Any recommended way to encode and pass?

Also, it seems that with Java SDK, we don’t have a way to assign a business-level identifier as Activity ID yet. Wanted to double check if I missed something.

I’m trying to complete an activity asynchronously, and am not sure how to best pass the activity task token or assign my own activity ID which will be easier to pass. Thanks!