Skip to content

Commit b15f114

Browse files
georgepsarakisOmer Katz
authored andcommitted
Document ignore_result task execution option (celery#4745)
- Add Changelog entries regarding ignore_result task execution option and Redis result consumer fixes.
1 parent 17b7f4e commit b15f114

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

Changelog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ an overview of what's new in Celery 4.2.
1111
4.2.0
1212
=====
1313

14+
- **Task**: Add ``ignore_result`` as task execution option (#4709, #3834)
15+
16+
Contributed by **Andrii Kostenko** and **George Psarakis**.
17+
18+
- **Redis Result Backend**: Do not create PubSub subscriptions when results are ignored (#4709, #3834)
19+
20+
Contributed by **Andrii Kostenko** and **George Psarakis**.
21+
22+
- **Redis Result Backend**: Result consumer always unsubscribes when task state is ready (#4666)
23+
24+
Contributed by **George Psarakis**.
25+
1426
- **Development/Testing**: Add docker-compose and base Dockerfile for development (#4482)
1527

1628
Contributed by **Chris Mitchell**.

docs/userguide/calling.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,25 @@ the workers :option:`-Q <celery worker -Q>` argument:
578578

579579
To find out more about routing, please see :ref:`guide-routing`.
580580

581+
.. _calling-results:
582+
583+
Results options
584+
===============
585+
586+
You can enable or disable result storage using the ``ignore_result`` option::
587+
588+
result = add.apply_async(1, 2, ignore_result=True)
589+
result.get() # -> None
590+
591+
# Do not ignore result (default)
592+
result = add.apply_async(1, 2, ignore_result=False)
593+
result.get() # -> 3
594+
595+
596+
.. seealso::
597+
598+
For more information on tasks, please see :ref:`guide-tasks`.
599+
581600
Advanced Options
582601
----------------
583602

docs/userguide/tasks.rst

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,9 +1047,9 @@ the most appropriate for your needs.
10471047

10481048
.. warning::
10491049

1050-
Backends use resources to store and transmit results. To ensure
1051-
that resources are released, you must eventually call
1052-
:meth:`[email protected]` or :meth:`[email protected]` on
1050+
Backends use resources to store and transmit results. To ensure
1051+
that resources are released, you must eventually call
1052+
:meth:`[email protected]` or :meth:`[email protected]` on
10531053
EVERY :class:`~@AsyncResult` instance returned after calling
10541054
a task.
10551055

@@ -1634,6 +1634,34 @@ wastes time and resources.
16341634
Results can even be disabled globally using the :setting:`task_ignore_result`
16351635
setting.
16361636

1637+
.. versionadded::4.2
1638+
1639+
Results can be enabled/disabled on a per-execution basis, by passing the ``ignore_result`` boolean parameter,
1640+
when calling ``apply_async`` or ``delay``.
1641+
1642+
.. code-block:: python
1643+
1644+
@app.task
1645+
def mytask(x, y):
1646+
return x + y
1647+
1648+
# No result will be stored
1649+
result = mytask.apply_async(1, 2, ignore_result=True)
1650+
print result.get() # -> None
1651+
1652+
# Result will be stored
1653+
result = mytask.apply_async(1, 2, ignore_result=False)
1654+
print result.get() # -> 3
1655+
1656+
By default tasks will *not ignore results* (``ignore_result=False``) when a result backend is configured.
1657+
1658+
1659+
The option precedence order is the following:
1660+
1661+
1. Global :setting:`task_ignore_result`
1662+
2. :attr:`[email protected]_result` option
1663+
3. Task execution option ``ignore_result``
1664+
16371665
More optimization tips
16381666
----------------------
16391667

0 commit comments

Comments
 (0)