How to get the activity state at the workflow level?

I would like to have a way to get the state (percentage of completeness or other) from an activity to the workflow. So the workflow can return it as the part of a query to the workflow or use it for reasoning on the rest of the execution. Now I see two ways:

  1. Activity heartbeats can have some data (percentage or any other). But I cannot find a way to read about the activity heartbeats from the workflow.

  2. Signals. An activity can signal some data to the workflow as some milestones reached by the activity (every 10 percent, for example). And the workflow will be able to read the data and reason or send it as the result of the query.

What is the best way to do this?

From outside of workflow you can use DescribeWorkflowExecution call that returns all pending activities information including data included in the last heartbeat.

I would go with the signal approach you described if the workflow has to take action based on activity reaching a certain milestone.