Client helpers
Optional helpers for the client application (see Client: revoking tasks). Only
boto3 is needed.
Client-side helpers (optional): the parts of Celery that need the runner’s help.
A Celery client cannot revoke a task of this runner by itself: app.control.revoke
broadcasts a message to workers, and there are no workers to receive it. The helpers
here do it through the result backend instead, which the runner already reads:
from celery_cloud.client import install
install(app) # once, after configuring the Celery app
result.revoke() # now works: a task that has not started never starts
How it works: revoke writes a REVOKED result for the task with a revoked
flag. A task that has not started yet is skipped by the runner. A task that is already
running is only flagged: it keeps running unless its code checks
self.is_revoked() (cooperative cancellation), because a running Python function
cannot be stopped safely from outside.
Only boto3 is needed (no runner settings are read).
- celery_cloud.client.backend_location(result_backend: str) tuple[str, str][source]
(region, table)of adynamodb://@region/tableresult backend URL.
- celery_cloud.client.install(app: Any, *, ttl_seconds: int = 86400) None[source]
Make
app.control.revoke/AsyncResult.revokework with this runner.Reads the Region and table from the app’s
result_backend.terminateandsignalare accepted and ignored: a running task is flagged, not killed.
- celery_cloud.client.revoke(task_id: str, *, table: str, region: str, ttl_seconds: int = 86400, serializer: str = 'json', client: Any = None) str[source]
Revoke a task.
- Parameters:
task_id – The Celery task id.
table – The DynamoDB result table.
region – The Region of the table.
ttl_seconds – How long the
REVOKEDmarker is kept (0 = forever; it only expires if TTL is enabled on the table for thettlattribute).serializer – The
result_serializerof the client (json, msgpack or yaml).client – A DynamoDB client (for tests); created from
regionby default.
- Returns:
"revoked"when the task had not started (it will never run), or"flagged"when it had already started or finished (the flag is only seen by a task that checksself.is_revoked()).