Signals

Signals: hooks that run around every task, like Celery’s task_prerun & co.

Connect a receiver in a module listed in INIT_MODULES (imported once, when the function starts) so it is registered before the first task runs:

from celery_cloud.signals import task_failure

@task_failure.connect
def report(task_id=None, task=None, exception=None, **kwargs):
    ...

Receivers are called with keyword arguments, so declare **kwargs: new ones may be added. A receiver that raises is logged and ignored; it never breaks the task.

Signal

Keyword arguments

task_prerun

task_id, task (name), args, kwargs

task_postrun

the above + retval and state (SUCCESS, FAILURE, RETRY, IGNORED, REJECTED)

task_success

task_id, task, result

task_failure

task_id, task, exception, traceback

task_retry

task_id, task, reason, eta

class celery_cloud.signals.Signal(name: str)[source]

Bases: object

A list of receivers that are called with keyword arguments.

__init__(name: str) → None[source]
connect(receiver: Callable[[...], Any]) → Callable[[...], Any][source]

Register receiver (usable as a decorator); twice is a no-op.

disconnect(receiver: Callable[[...], Any]) → None[source]
send(**kwargs: Any) → None[source]

Call every receiver; their errors are logged, never raised.

The signals

celery_cloud.signals.task_prerun

A list of receivers that are called with keyword arguments.

celery_cloud.signals.task_postrun

A list of receivers that are called with keyword arguments.

celery_cloud.signals.task_success

A list of receivers that are called with keyword arguments.

celery_cloud.signals.task_failure

A list of receivers that are called with keyword arguments.

celery_cloud.signals.task_retry

A list of receivers that are called with keyword arguments.