documentation icon indicating copy to clipboard operation
documentation copied to clipboard

[Features] Async Activity Completion is missing in Python

Open rachfop opened this issue 3 years ago • 1 comments

Async Activity Completion is missing is Python


You can provide a code snippet in the comments or a link to the line numbers of the samples-repo. Once added, I'll update the app-dev page with the new code snippet.

rachfop avatar Aug 18 '22 20:08 rachfop

The link in this issue is now broken. Instead of https://docs.temporal.io/application-development/features?lang=python#async-activity-completion it should be https://docs.temporal.io/application-development/features?lang=python#asynchronous-activity-completion.

https://github.com/temporalio/samples-python/blob/main/hello/hello_async_activity_completion.py is the full sample, but basically inside an activity to mark it as completing async, you would:

# Capture token for later completion
captured_token = activity.info().task_token
activity.raise_complete_async()

(this could also work with user-defined activity IDs)

To get a handle to update the activity outside the activity, given a client you would:

handle = my_client.get_async_activity_handle(task_token=captured_token)

Then, on that handle, you can call heartbeat, complete, fail, and report_cancellation to update the activity.

cretz avatar Sep 01 '22 16:09 cretz