Signals

Kuyruk can be extended via signals. Kuyruk has a signalling support via Blinker library.

Example

Here is an example for clearing the SQLAlchemy’s scoped_session before executing the function and commiting it after the task is executed:

from kuyruk import Kuyruk
from kuyruk.signals import task_prerun, task_postrun

from myapp.orm import Session

kuyruk = Kuyruk()

@task_prerun.connect_via(kuyruk)
def open_session(sender, task=None, **extra):
    task.session = Session()

@task_postrun.connect_via(kuyruk)
def close_session(sender, task=None, **extra):
    task.session.close()

@kuyruk.task
def task_with_a_session():
    session = task_with_a_session.session
    # Work with the session...
    session.commit()

List of Signals

kuyruk.signals.task_init = <blinker.base.Signal object>

Sent when the task decorator is applied.

Arguments:
  • sender: Kuyruk object
  • task: Task object
kuyruk.signals.task_preapply = <blinker.base.Signal object>

Sent before the task is applied.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
kuyruk.signals.task_postapply = <blinker.base.Signal object>

Sent after the task is applied.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
kuyruk.signals.task_prerun = <blinker.base.Signal object>

Sent before the wrapped function is executed.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
kuyruk.signals.task_postrun = <blinker.base.Signal object>

Sent after the wrapped function is executed.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
kuyruk.signals.task_success = <blinker.base.Signal object>

Sent when the wrapped function is returned.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
kuyruk.signals.task_error = <blinker.base.Signal object>

Sent when the wrapped function raises an exception.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
  • exc_info: Return value of sys.exc_info()
kuyruk.signals.task_failure = <blinker.base.Signal object>

Sent when the task fails after all retries(if any).

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
  • exc_info: Return value of sys.exc_info()
kuyruk.signals.task_presend = <blinker.base.Signal object>

Sent before the task is sent to queue.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
  • description: dict representation of the task
kuyruk.signals.task_postsend = <blinker.base.Signal object>

Sent after the task is sent to queue.

Arguments:
  • sender: Kuyruk object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
  • description: dict representation of the task
kuyruk.signals.worker_failure = <blinker.base.Signal object>

Sent when the task fails.

Arguments:
  • sender: Kuyruk object
  • worker: The Worker object
  • task: Task object
  • args: Positional arguments to the task
  • kwargs: Keyword arguments to the task
  • description: dict representation of the task
  • exc_info: Return value of sys.exc_info()
kuyruk.signals.worker_init = <blinker.base.Signal object>

Sent when the worker is initialized.

Arguments:
  • sender: Kuyruk object
  • worker: The Worker object
kuyruk.signals.worker_start = <blinker.base.Signal object>

Sent when the worker is started.

Arguments:
  • sender: Kuyruk object
  • worker: The Worker object
kuyruk.signals.worker_shutdown = <blinker.base.Signal object>

Sent when the worker shuts down.

Arguments:
  • sender: Kuyruk object
  • worker: The Worker object