|
@@ -1,9 +1,10 @@
|
|
"""
|
|
"""
|
|
|
|
+==============
|
|
celery.signals
|
|
celery.signals
|
|
==============
|
|
==============
|
|
|
|
|
|
-Signals allows decoupled applications receive notifications when actions
|
|
|
|
-occur elsewhere in the framework.
|
|
|
|
|
|
+Signals allows decoupled applications to receive notifications when certain actions
|
|
|
|
+occur.
|
|
|
|
|
|
:copyright: (c) 2009 - 2011 by Ask Solem.
|
|
:copyright: (c) 2009 - 2011 by Ask Solem.
|
|
:license: BSD, see LICENSE for more details.
|
|
:license: BSD, see LICENSE for more details.
|
|
@@ -14,12 +15,12 @@ occur elsewhere in the framework.
|
|
.. _signal-basics:
|
|
.. _signal-basics:
|
|
|
|
|
|
Basics
|
|
Basics
|
|
-------
|
|
|
|
|
|
+======
|
|
|
|
|
|
Several kinds of events trigger signals, you can connect to these signals
|
|
Several kinds of events trigger signals, you can connect to these signals
|
|
to perform actions as they trigger.
|
|
to perform actions as they trigger.
|
|
|
|
|
|
-Example connecting to the :data:`task_sent` signal:
|
|
|
|
|
|
+Example connecting to the :signal:`task_sent` signal:
|
|
|
|
|
|
.. code-block:: python
|
|
.. code-block:: python
|
|
|
|
|
|
@@ -33,7 +34,7 @@ Example connecting to the :data:`task_sent` signal:
|
|
|
|
|
|
|
|
|
|
Some signals also have a sender which you can filter by. For example the
|
|
Some signals also have a sender which you can filter by. For example the
|
|
-:data:`task_sent` signal uses the task name as a sender, so you can
|
|
|
|
|
|
+:signal:`task_sent` signal uses the task name as a sender, so you can
|
|
connect your handler to be called only when tasks with name `"tasks.add"`
|
|
connect your handler to be called only when tasks with name `"tasks.add"`
|
|
has been sent by providing the `sender` argument to
|
|
has been sent by providing the `sender` argument to
|
|
:class:`~celery.utils.dispatch.signal.Signal.connect`:
|
|
:class:`~celery.utils.dispatch.signal.Signal.connect`:
|
|
@@ -45,135 +46,170 @@ has been sent by providing the `sender` argument to
|
|
.. _signal-ref:
|
|
.. _signal-ref:
|
|
|
|
|
|
Signals
|
|
Signals
|
|
--------
|
|
|
|
|
|
+=======
|
|
|
|
|
|
Task Signals
|
|
Task Signals
|
|
-~~~~~~~~~~~~
|
|
|
|
|
|
+------------
|
|
|
|
+
|
|
|
|
+.. signal:: task_sent
|
|
|
|
+
|
|
|
|
+task_sent
|
|
|
|
+~~~~~~~~~
|
|
|
|
+
|
|
|
|
+Dispatched when a task has been sent to the broker.
|
|
|
|
+Note that this is executed in the client process, the one sending
|
|
|
|
+the task, not in the worker.
|
|
|
|
+
|
|
|
|
+Sender is the name of the task being sent.
|
|
|
|
+
|
|
|
|
+Provides arguments:
|
|
|
|
+
|
|
|
|
+* task_id
|
|
|
|
+ Id of the task to be executed.
|
|
|
|
+
|
|
|
|
+* task
|
|
|
|
+ The task being executed.
|
|
|
|
+
|
|
|
|
+* args
|
|
|
|
+ the tasks positional arguments.
|
|
|
|
+
|
|
|
|
+* kwargs
|
|
|
|
+ The tasks keyword arguments.
|
|
|
|
|
|
-.. data:: task_sent
|
|
|
|
|
|
+* eta
|
|
|
|
+ The time to execute the task.
|
|
|
|
|
|
- Dispatched when a task has been sent to the broker.
|
|
|
|
- Note that this is executed in the client process, the one sending
|
|
|
|
- the task, not in the worker.
|
|
|
|
|
|
+* taskset
|
|
|
|
+ Id of the taskset this task is part of (if any).
|
|
|
|
|
|
- Sender is the name of the task being sent.
|
|
|
|
|
|
+.. signal:: task_prerun
|
|
|
|
|
|
- Provides arguments:
|
|
|
|
|
|
+task_prerun
|
|
|
|
+~~~~~~~~~~~
|
|
|
|
|
|
- * task_id
|
|
|
|
- Id of the task to be executed.
|
|
|
|
|
|
+Dispatched before a task is executed.
|
|
|
|
|
|
- * task
|
|
|
|
- The task being executed.
|
|
|
|
|
|
+Sender is the task class being executed.
|
|
|
|
|
|
- * args
|
|
|
|
- the tasks positional arguments.
|
|
|
|
|
|
+Provides arguments:
|
|
|
|
|
|
- * kwargs
|
|
|
|
- The tasks keyword arguments.
|
|
|
|
|
|
+* task_id
|
|
|
|
+ Id of the task to be executed.
|
|
|
|
|
|
- * eta
|
|
|
|
- The time to execute the task.
|
|
|
|
|
|
+* task
|
|
|
|
+ The task being executed.
|
|
|
|
|
|
- * taskset
|
|
|
|
- Id of the taskset this task is part of (if any).
|
|
|
|
|
|
+* args
|
|
|
|
+ the tasks positional arguments.
|
|
|
|
|
|
-.. data:: task_prerun
|
|
|
|
|
|
+* kwargs
|
|
|
|
+ The tasks keyword arguments.
|
|
|
|
|
|
- Dispatched before a task is executed.
|
|
|
|
|
|
+.. signal:: task_postrun
|
|
|
|
|
|
- Sender is the task class being executed.
|
|
|
|
|
|
+task_postrun
|
|
|
|
+~~~~~~~~~~~~
|
|
|
|
|
|
- Provides arguments:
|
|
|
|
|
|
+Dispatched after a task has been executed.
|
|
|
|
|
|
- * task_id
|
|
|
|
- Id of the task to be executed.
|
|
|
|
|
|
+Sender is the task class executed.
|
|
|
|
|
|
- * task
|
|
|
|
- The task being executed.
|
|
|
|
|
|
+Provides arguments:
|
|
|
|
|
|
- * args
|
|
|
|
- the tasks positional arguments.
|
|
|
|
|
|
+* task_id
|
|
|
|
+ Id of the task to be executed.
|
|
|
|
|
|
- * kwargs
|
|
|
|
- The tasks keyword arguments.
|
|
|
|
|
|
+* task
|
|
|
|
+ The task being executed.
|
|
|
|
|
|
-.. data:: task_postrun
|
|
|
|
|
|
+* args
|
|
|
|
+ The tasks positional arguments.
|
|
|
|
|
|
- Dispatched after a task has been executed.
|
|
|
|
|
|
+* kwargs
|
|
|
|
+ The tasks keyword arguments.
|
|
|
|
|
|
- Sender is the task class executed.
|
|
|
|
|
|
+* retval
|
|
|
|
+ The return value of the task.
|
|
|
|
|
|
- Provides arguments:
|
|
|
|
|
|
+.. signal:: task_failure
|
|
|
|
|
|
- * task_id
|
|
|
|
- Id of the task to be executed.
|
|
|
|
|
|
+task_failure
|
|
|
|
+~~~~~~~~~~~~
|
|
|
|
|
|
- * task
|
|
|
|
- The task being executed.
|
|
|
|
|
|
+Dispatched when a task fails.
|
|
|
|
|
|
- * args
|
|
|
|
- The tasks positional arguments.
|
|
|
|
|
|
+Sender is the task class executed.
|
|
|
|
|
|
- * kwargs
|
|
|
|
- The tasks keyword arguments.
|
|
|
|
|
|
+Provides arguments:
|
|
|
|
|
|
- * retval
|
|
|
|
- The return value of the task.
|
|
|
|
|
|
+* task_id
|
|
|
|
+ Id of the task.
|
|
|
|
|
|
-.. data:: task_failure
|
|
|
|
|
|
+* exception
|
|
|
|
+ Exception instance raised.
|
|
|
|
|
|
- Dispatched when a task fails.
|
|
|
|
|
|
+* args
|
|
|
|
+ Positional arguments the task was called with.
|
|
|
|
|
|
- Sender is the task class executed.
|
|
|
|
|
|
+* kwargs
|
|
|
|
+ Keyword arguments the task was called with.
|
|
|
|
|
|
- Provides arguments:
|
|
|
|
|
|
+* traceback
|
|
|
|
+ Stack trace object.
|
|
|
|
|
|
- * task_id
|
|
|
|
- Id of the task.
|
|
|
|
- * exception
|
|
|
|
- Exception instance raised.
|
|
|
|
- * args
|
|
|
|
- Positional arguments the task was called with.
|
|
|
|
- * kwargs
|
|
|
|
- Keyword arguments the task was called with.
|
|
|
|
- * traceback
|
|
|
|
- Stack trace object.
|
|
|
|
- * einfo
|
|
|
|
- The :class:`celery.datastructures.ExceptionInfo` instance.
|
|
|
|
|
|
+* einfo
|
|
|
|
+ The :class:`celery.datastructures.ExceptionInfo` instance.
|
|
|
|
|
|
Worker Signals
|
|
Worker Signals
|
|
-~~~~~~~~~~~~~~
|
|
|
|
|
|
+--------------
|
|
|
|
+
|
|
|
|
+.. signal:: worker_init
|
|
|
|
|
|
-.. data:: worker_init
|
|
|
|
|
|
+worker_init
|
|
|
|
+~~~~~~~~~~~
|
|
|
|
|
|
- Dispatched before the worker is started.
|
|
|
|
|
|
+Dispatched before the worker is started.
|
|
|
|
+
|
|
|
|
+.. signal:: worker_ready
|
|
|
|
+
|
|
|
|
+worker_ready
|
|
|
|
+~~~~~~~~~~~~
|
|
|
|
|
|
-.. data:: worker_ready
|
|
|
|
|
|
+Dispatched when the worker is ready to accept work.
|
|
|
|
|
|
- Dispatched when the worker is ready to accept work.
|
|
|
|
|
|
+.. signal:: worker_process_init
|
|
|
|
|
|
-.. data:: worker_process_init
|
|
|
|
|
|
+worker_process_init
|
|
|
|
+~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
- Dispatched by each new pool worker process when it starts.
|
|
|
|
|
|
+Dispatched by each new pool worker process when it starts.
|
|
|
|
|
|
-.. data:: worker_shutdown
|
|
|
|
|
|
+.. signal:: worker_shutdown
|
|
|
|
|
|
- Dispatched when the worker is about to shut down.
|
|
|
|
|
|
+worker_shutdown
|
|
|
|
+~~~~~~~~~~~~~~~
|
|
|
|
+
|
|
|
|
+Dispatched when the worker is about to shut down.
|
|
|
|
|
|
Celerybeat Signals
|
|
Celerybeat Signals
|
|
-~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
+------------------
|
|
|
|
+
|
|
|
|
+.. signal:: beat_init
|
|
|
|
|
|
-.. data:: beat_init
|
|
|
|
|
|
+beat_init
|
|
|
|
+~~~~~~~~~
|
|
|
|
|
|
- Dispatched when celerybeat starts (either standalone or embedded).
|
|
|
|
- Sender is the :class:`celery.beat.Service` instance.
|
|
|
|
|
|
+Dispatched when celerybeat starts (either standalone or embedded).
|
|
|
|
+Sender is the :class:`celery.beat.Service` instance.
|
|
|
|
|
|
-.. data:: beat_embedded_init
|
|
|
|
|
|
+.. signal:: beat_embedded_init
|
|
|
|
+
|
|
|
|
+beat_embedded_init
|
|
|
|
+~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
- Dispatched in addition to the :data:`beat_init` signal when celerybeat is
|
|
|
|
- started as an embedded process. Sender is the
|
|
|
|
- :class:`celery.beat.Service` instance.
|
|
|
|
|
|
+Dispatched in addition to the :signal:`beat_init` signal when celerybeat is
|
|
|
|
+started as an embedded process. Sender is the
|
|
|
|
+:class:`celery.beat.Service` instance.
|
|
|
|
|
|
|
|
|
|
"""
|
|
"""
|