mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-12-19 23:35:04 +01:00
MyST conversion
This commit is contained in:
@@ -15,8 +15,8 @@ Alliance Auth is an online web application and as such the user expects fast and
|
||||
As a rule of thumb we therefore recommend to use celery tasks for every process that can take longer than 1 sec to complete (also think about how long your process might take with large amounts of data).
|
||||
|
||||
:::{note}
|
||||
Another solution for dealing with long response time in particular when loading pages is to load parts of a page asynchronously, for example with AJAX.
|
||||
```
|
||||
Another solution for dealing with long response time in particular when loading pages is to load parts of a page asynchronously, for example with AJAX.
|
||||
:::
|
||||
|
||||
### Recurrence
|
||||
|
||||
@@ -39,7 +39,7 @@ Please use the following approach to ensure your tasks are working properly with
|
||||
|
||||
Here is an example implementation of a task:
|
||||
|
||||
```Python
|
||||
```python
|
||||
import logging
|
||||
from celery import shared_task
|
||||
|
||||
@@ -53,7 +53,7 @@ def example():
|
||||
|
||||
This task can then be started from any another Python module like so:
|
||||
|
||||
```Python
|
||||
```python
|
||||
from .tasks import example
|
||||
|
||||
example.delay()
|
||||
@@ -79,7 +79,7 @@ However, many long running tasks consist of several smaller processes that need
|
||||
|
||||
Example implementation for a celery chain:
|
||||
|
||||
```Python
|
||||
```python
|
||||
import logging
|
||||
from celery import shared_task, chain
|
||||
|
||||
@@ -106,11 +106,11 @@ In this example we fist add 10 example tasks that need to run one after the othe
|
||||
The list of task signatures is then converted to a chain and started asynchronously.
|
||||
|
||||
:::{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>`_.
|
||||
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.
|
||||
:::
|
||||
|
||||
## How can I define periodic tasks for my app?
|
||||
@@ -119,7 +119,7 @@ Periodic tasks are normal celery tasks which are added the scheduler for periodi
|
||||
|
||||
Example setting:
|
||||
|
||||
```Python
|
||||
```python
|
||||
CELERYBEAT_SCHEDULE['structures_update_all_structures'] = {
|
||||
'task': 'structures.tasks.update_all_structures',
|
||||
'schedule': crontab(minute='*/30'),
|
||||
@@ -149,23 +149,23 @@ In Alliance Auth we have defined task priorities from 0 - 9 as follows:
|
||||
```
|
||||
|
||||
:::{warning}
|
||||
Please make sure to use task priorities with care and especially do not use higher priorities without a good reason. All apps including Alliance Auth share the same task queues, so using higher task priorities excessively can potentially prevent more important tasks (of other apps) from completing on time.
|
||||
Please make sure to use task priorities with care and especially do not use higher priorities without a good reason. All apps including Alliance Auth share the same task queues, so using higher task priorities excessively can potentially prevent more important tasks (of other apps) from completing on time.
|
||||
|
||||
You also want to make sure to run use lower priorities if you have a large amount of tasks or long running tasks, which are not super urgent. (e.g. the regular update of all Eve characters from ESI runs with priority 7)
|
||||
You also want to make sure to run use lower priorities if you have a large amount of tasks or long running tasks, which are not super urgent. (e.g. the regular update of all Eve characters from ESI runs with priority 7)
|
||||
:::
|
||||
:::{hint}
|
||||
If no priority is specified all tasks will be started with the default priority, which is 5.
|
||||
If no priority is specified all tasks will be started with the default priority, which is 5.
|
||||
:::
|
||||
To run a task with a different priority you need to specify it when starting it.
|
||||
|
||||
Example for starting a task with priority 3:
|
||||
|
||||
```Python
|
||||
```python
|
||||
example.apply_async(priority=3)
|
||||
```
|
||||
|
||||
:::{hint}
|
||||
For defining a priority to tasks you can not use the convenient shortcut ``delay()``, but instead need to start a task with ``apply_async()``, which also requires you to pass parameters to your task function differently. Please check out the `official docs <https://docs.celeryproject.org/en/stable/reference/celery.app.task.html#celery.app.task.Task.apply_async>`_ for details.
|
||||
For defining a priority to tasks you can not use the convenient shortcut ``delay()``, but instead need to start a task with ``apply_async()``, which also requires you to pass parameters to your task function differently. Please check out the `official docs <https://docs.celeryproject.org/en/stable/reference/celery.app.task.html#celery.app.task.Task.apply_async>`_ for details.
|
||||
:::
|
||||
|
||||
## What special features should I be aware of?
|
||||
@@ -179,18 +179,18 @@ Celery-once is a celery extension "that allows you to prevent multiple execution
|
||||
We use a custom backend for celery_once in Alliance Auth defined [here](https://gitlab.com/allianceauth/allianceauth/-/blob/master/allianceauth/services/tasks.py#L14)
|
||||
You can import it for use like so:
|
||||
|
||||
```Python
|
||||
```python
|
||||
from allianceauth.services.tasks import QueueOnce
|
||||
```
|
||||
|
||||
An example of AllianceAuth's use within the `@sharedtask` decorator, can be seen [here](https://gitlab.com/allianceauth/allianceauth/-/blob/master/allianceauth/services/modules/discord/tasks.py#L62) in the discord module
|
||||
You can use it like so:
|
||||
|
||||
```Python
|
||||
```python
|
||||
@shared_task(bind=True, name='your_modules.update_task', base=QueueOnce)
|
||||
```
|
||||
|
||||
Please see the [official documentation](hhttps://pypi.org/project/celery_once/) of celery-once for details.
|
||||
Please see the [official documentation](https://pypi.org/project/celery_once/) of celery-once for details.
|
||||
|
||||
### task priorities
|
||||
|
||||
|
||||
Reference in New Issue
Block a user