Skip to content

Commit

Permalink
Reorganize docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Jun 21, 2021
1 parent 2ee6562 commit 2235ca1
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions docs/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,48 @@ API docs:
* :py:meth:`TaskWrapper.is_revoked` for checking the status of the task
function itself.

Canceling or pausing periodic tasks
-----------------------------------

The ``revoke()`` and ``restore()`` methods support some additional options
which may be especially useful for :py:meth:`~Huey.periodic_task`.

The :py:meth:`~TaskWrapper.revoke` method accepts two optional parameters:

* ``revoke_once`` - boolean flag, if set then only the next occurrence of the
task will be revoked, after which it will be restored automatically.
* ``revoke_until`` - datetime, which specifies the time at which the task
should be automatically restored.

For example, suppose we have a task that sends email notifications, but our
mail server goes down and won't be fixed for a while. We can revoke the task
for a couple of hours, after which time it will start executing again:

.. code-block:: python
@huey.periodic_task(crontab(minute='0', hour='*'))
def send_notification_emails():
# ... code to send emails ...
Here is how we might revoke the task for the next 3 hours:

.. code-block:: pycon
>>> now = datetime.datetime.now()
>>> eta = now + datetime.timedelta(hours=3)
>>> send_notification_emails.revoke(revoke_until=eta)
Alternatively, we could use ``revoke_once=True`` to just skip the next
execution of the task:

.. code-block:: pycon
>>> send_notification_emails.revoke(revoke_once=True)
At any time, the task can be restored using the usual
:py:meth:`~TaskWrapper.restore` method, and it's status can be checked using
the :py:meth:`~TaskWrapper.is_revoked` method.

Task expiration
---------------

Expand Down Expand Up @@ -442,48 +484,6 @@ Expiration times can also be specified when scheduling tasks:
eta=one_hr,
expires=one_hr + timedelta(seconds=60))
Canceling or pausing periodic tasks
-----------------------------------

The ``revoke()`` and ``restore()`` methods support some additional options
which may be especially useful for :py:meth:`~Huey.periodic_task`.

The :py:meth:`~TaskWrapper.revoke` method accepts two optional parameters:

* ``revoke_once`` - boolean flag, if set then only the next occurrence of the
task will be revoked, after which it will be restored automatically.
* ``revoke_until`` - datetime, which specifies the time at which the task
should be automatically restored.

For example, suppose we have a task that sends email notifications, but our
mail server goes down and won't be fixed for a while. We can revoke the task
for a couple of hours, after which time it will start executing again:

.. code-block:: python
@huey.periodic_task(crontab(minute='0', hour='*'))
def send_notification_emails():
# ... code to send emails ...
Here is how we might revoke the task for the next 3 hours:

.. code-block:: pycon
>>> now = datetime.datetime.now()
>>> eta = now + datetime.timedelta(hours=3)
>>> send_notification_emails.revoke(revoke_until=eta)
Alternatively, we could use ``revoke_once=True`` to just skip the next
execution of the task:

.. code-block:: pycon
>>> send_notification_emails.revoke(revoke_once=True)
At any time, the task can be restored using the usual
:py:meth:`~TaskWrapper.restore` method, and it's status can be checked using
the :py:meth:`~TaskWrapper.is_revoked` method.

Task pipelines
--------------

Expand Down

0 comments on commit 2235ca1

Please sign in to comment.