Switch the doc example to use group instead of chain for long running tasks

This commit is contained in:
r0kym 2025-03-20 18:47:19 +01:00
parent 055077fa77
commit 4de0774f15

View File

@ -81,7 +81,7 @@ Example implementation for a celery chain:
```python ```python
from allianceauth.services.hooks import get_extension_logger from allianceauth.services.hooks import get_extension_logger
from celery import shared_task, chain from celery import shared_task, group
logger = get_extension_logger(__name__) logger = get_extension_logger(__name__)
@ -98,18 +98,23 @@ def long_runner():
task_signature = example.si() task_signature = example.si()
my_tasks.append(task_signature) my_tasks.append(task_signature)
chain(my_tasks).delay() group(my_tasks).delay()
``` ```
In this example, we first add 10 example tasks that need to run one after the other to a list. This can be done by creating a so-called signature for a task. Those signatures are a kind of wrapper for tasks and can be used in various ways to compose work flow for tasks. In this example, we first add 10 example tasks that need to run one after the other to a list. This can be done by creating a so-called signature for a task. Those signatures are a kind of wrapper for tasks and can be used in various ways to compose work flow for tasks.
The list of task signatures is then converted to a chain and started asynchronously. The list of task signatures is then converted to a chain and started asynchronously.
:::{note}
In this example we import group to execute all tasks independently.
If you wish to run them in order (and stop if a tasks fail) you can use `celery.chain` instead of `celery.group`
For more information on signature and work flows see the official documentation on [Canvas](https://docs.celeryproject.org/en/latest/userguide/canvas.html).
:::
:::{hint} :::{hint}
In our example we use ``si()``, which is a shortcut for "immutable signatures" and prevents us from having to deal with result sharing between tasks. In our example we use ``si()``, which is a shortcut for "immutable signatures" and prevents us from having to deal with result sharing between tasks.
For more information on signature and work flows see the official documentation on `Canvas <https://docs.celeryproject.org/en/latest/userguide/canvas.html>`_.
In this context, please note that Alliance Auth currently only supports chaining because all other variants require a so-called results back, which Alliance Auth does not have. In this context, please note that Alliance Auth currently only supports chaining because all other variants require a so-called results back, which Alliance Auth does not have.
::: :::