Skip to content

Commit

Permalink
Add example for SIGNAL_INTERRUPTED
Browse files Browse the repository at this point in the history
Replaces #797
  • Loading branch information
coleifer committed May 16, 2024
1 parent 2e3f08b commit e039644
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/signals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ The following signal will be sent:
* ``SIGNAL_REVOKED`` - this is sent before the task enters the "executing"
state. When a task is revoked, no other signals will be sent.

Using SIGNAL_INTERRUPTED
^^^^^^^^^^^^^^^^^^^^^^^^

The correct way to shut-down the Huey consumer is to send a ``SIGINT`` signal
to the worker process (e.g. Ctrl+C) - this initiates a graceful shutdown.
Sometimes, however, you may need to shutdown the consumer using ``SIGTERM`` -
this immediately stops the consumer. Any tasks that are currently being
executed are then "lost" and will not be retried by default (see also:
:ref:`consumer-shutdown`).

To avoid losing these tasks, you can use a ``SIGNAL_INTERRUPTED`` handler to
re-enqueue them:

.. code-block:: python
@huey.signal(SIGNAL_INTERRUPTED)
def on_interrupted(signal, task, *args, **kwargs):
# The consumer was shutdown before `task` finished executing.
# Re-enqueue it.
huey.enqueue(task)
Performance considerations
--------------------------

Expand Down

0 comments on commit e039644

Please sign in to comment.