mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2026-02-05 14:46:20 +01:00
Merge branch 'master' of gitlab.com:allianceauth/allianceauth into v5.x
This commit is contained in:
@@ -81,7 +81,7 @@ Example implementation for a celery chain:
|
||||
|
||||
```python
|
||||
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__)
|
||||
|
||||
@@ -98,18 +98,23 @@ def long_runner():
|
||||
task_signature = example.si()
|
||||
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.
|
||||
|
||||
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}
|
||||
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.
|
||||
:::
|
||||
|
||||
@@ -266,7 +271,7 @@ Every Alliance Auth installation will come with a couple of special celery relat
|
||||
|
||||
Celery-once is a celery extension "that allows you to prevent multiple execution and queuing of celery tasks". What that means is that you can ensure that only one instance of a celery task runs at any given time. This can be useful, for example, if you do not want multiple instances of your task to talk to the same external service at the same time.
|
||||
|
||||
We use a custom backend for celery_once in Alliance Auth defined in [allianceauth.services.tasks](https://gitlab.com/allianceauth/allianceauth/-/blob/master/allianceauth/services/tasks.py#L14)
|
||||
We use a custom backend for celery_once in Alliance Auth defined [allianceauth.services.tasks.celery_once](https://gitlab.com/allianceauth/allianceauth/-/blob/master/allianceauth/services/tasks.py#L14)
|
||||
You can import it for use like so:
|
||||
|
||||
```python
|
||||
|
||||
Reference in New Issue
Block a user