Browse Source

Document ignore_result task execution option (#4745)

- Add Changelog entries regarding ignore_result task execution option
  and Redis result consumer fixes.
George Psarakis 6 years ago
parent
commit
b15f11489b
3 changed files with 62 additions and 3 deletions
  1. 12 0
      Changelog
  2. 19 0
      docs/userguide/calling.rst
  3. 31 3
      docs/userguide/tasks.rst

+ 12 - 0
Changelog

@@ -11,6 +11,18 @@ an overview of what's new in Celery 4.2.
 4.2.0
 =====
 
+- **Task**: Add ``ignore_result`` as task execution option (#4709, #3834)
+
+    Contributed by **Andrii Kostenko** and **George Psarakis**.
+
+- **Redis Result Backend**: Do not create PubSub subscriptions when results are ignored (#4709, #3834)
+
+    Contributed by **Andrii Kostenko** and **George Psarakis**.
+
+- **Redis Result Backend**: Result consumer always unsubscribes when task state is ready (#4666)
+
+    Contributed by **George Psarakis**.
+
 - **Development/Testing**: Add docker-compose and base Dockerfile for development (#4482)
 
     Contributed by **Chris Mitchell**.

+ 19 - 0
docs/userguide/calling.rst

@@ -578,6 +578,25 @@ the workers :option:`-Q <celery worker -Q>` argument:
 
     To find out more about routing, please see :ref:`guide-routing`.
 
+.. _calling-results:
+
+Results options
+===============
+
+You can enable or disable result storage using the ``ignore_result`` option::
+
+    result = add.apply_async(1, 2, ignore_result=True)
+    result.get() # -> None
+
+    # Do not ignore result (default)
+    result = add.apply_async(1, 2, ignore_result=False)
+    result.get() # -> 3
+
+
+.. seealso::
+
+   For more information on tasks, please see :ref:`guide-tasks`.
+
 Advanced Options
 ----------------
 

+ 31 - 3
docs/userguide/tasks.rst

@@ -1047,9 +1047,9 @@ the most appropriate for your needs.
 
 .. warning::
 
-    Backends use resources to store and transmit results. To ensure 
-    that resources are released, you must eventually call 
-    :meth:`~@AsyncResult.get` or :meth:`~@AsyncResult.forget` on 
+    Backends use resources to store and transmit results. To ensure
+    that resources are released, you must eventually call
+    :meth:`~@AsyncResult.get` or :meth:`~@AsyncResult.forget` on
     EVERY :class:`~@AsyncResult` instance returned after calling
     a task.
 
@@ -1634,6 +1634,34 @@ wastes time and resources.
 Results can even be disabled globally using the :setting:`task_ignore_result`
 setting.
 
+.. versionadded::4.2
+
+Results can be enabled/disabled on a per-execution basis, by passing the ``ignore_result`` boolean parameter,
+when calling ``apply_async`` or ``delay``.
+
+.. code-block:: python
+
+    @app.task
+    def mytask(x, y):
+        return x + y
+
+    # No result will be stored
+    result = mytask.apply_async(1, 2, ignore_result=True)
+    print result.get() # -> None
+
+    # Result will be stored
+    result = mytask.apply_async(1, 2, ignore_result=False)
+    print result.get() # -> 3
+
+By default tasks will *not ignore results* (``ignore_result=False``) when a result backend is configured.
+
+
+The option precedence order is the following:
+
+1. Global :setting:`task_ignore_result`
+2. :attr:`~@Task.ignore_result` option
+3. Task execution option ``ignore_result``
+
 More optimization tips
 ----------------------