Activity implementation is an implementation of an activity interface. A single instance of the activities implementation is shared across multiple simultaneous activity invocations. Therefore, the activity implementation code must be thread safe.
The values passed to activities through invocation parameters or returned through a result value are recorded in the execution history. The entire execution history is transferred from the Temporal service to workflow workers when a workflow state needs to recover. A large execution history can thus adversely impact the performance of your workflow. Therefore, be mindful of the amount of data you transfer via activity invocation parameters or return values. Otherwise, no additional limitations exist on activity implementations.
Accessing Activity Info
The Activity class provides static getters to access information about the workflow that invoked it. Note that this information is stored in a thread local variable. Therefore, calls to Activity accessors succeed only in the thread that invoked the activity function.
Asynchronous Activity Completion
Sometimes an activity lifecycle goes beyond a synchronous method invocation. For example, a request can be put in a queue and later a reply comes and is picked up by a different worker process. The whole request-reply interaction can be modeled as a single Temporal activity.
To indicate that an activity should not be completed upon its method return, call
Activity.doNotCompleteOnReturn() from the
original activity thread. Then later, when replies come, complete the activity using ActivityCompletionClient.
To correlate activity invocation with completion, use either
TaskToken or workflow and activity Ids.
When the download is complete, the download service potentially calls back from a different process:
Activity Heart Beating
Some activities are long running. To react to a crash quickly, use a heartbeat mechanism.
Activity.heartbeat function lets the Temporal service know that the activity is still alive. You can piggyback
details on an activity heartbeat. If an activity times out, the last value of
details is included
ActivityTimeoutException delivered to a workflow. Then the workflow can pass the details to
the next activity invocation. This acts as a periodic checkpoint mechanism for the progress of an activity.