Using activities to poll for status

There are two ways to poll for status using any activity:

  1. just execute the activity and let it poll the api. If the api does not return what you want, have the activity fail and leverage the retry mechanism of the activity.
  • Pros: you can just fail the activity with the status so you can know what the status is. The downside is
  • Cons: you have to have the activity retry infinitely. Not sure if that is a concern
  1. In the activity, setup a for loop or channel and keep polling the api until the api gets you the desired state.
  • Pros: Any failures with the activity indicates system issues or api issues
  • Cons:
    • You have to use a heartbeat
    • You also have to some how log the status so you can monitor whats going on. From temporal side, you could report the status back to the workflow status but this is not desirable. You could put the status with the heart beat but not sure how you would even access it from temporal ui.

Both option works. I’m wondering what is the recommended?

Thanks,
Derek

  1. Retrying indefinitely is not a concern.
  2. You can use the DescribeWorkflowExecution API call to get the pending activities list. A pending activity record contains the last value of a heartbeat.

Both option works. I’m wondering what is the recommended?

I don’t think there is a hard rule. I usually recommend (2) for frequent polls and (1) for infrequent ones.