mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-12-18 23:05:07 +01:00
MyST conversion
This commit is contained in:
@@ -20,19 +20,21 @@ Typically a service will contain 5 key components:
|
||||
|
||||
The architecture looks something like this:
|
||||
|
||||
urls -------▶ Views
|
||||
▲ |
|
||||
| |
|
||||
| ▼
|
||||
ServiceHook ----▶ Tasks ----▶ Manager
|
||||
▲
|
||||
|
|
||||
|
|
||||
AllianceAuth
|
||||
```none
|
||||
urls -------▶ Views
|
||||
▲ |
|
||||
| |
|
||||
| ▼
|
||||
ServiceHook ----▶ Tasks ----▶ Manager
|
||||
▲
|
||||
|
|
||||
|
|
||||
AllianceAuth
|
||||
|
||||
|
||||
Where:
|
||||
Module --▶ Dependency/Import
|
||||
Where:
|
||||
Module --▶ Dependency/Import
|
||||
```
|
||||
|
||||
While this is the typical structure of the existing services modules, there is no enforcement of this structure and you are, effectively, free to create whatever architecture may be necessary. A service module need not even communicate with an external service, for example, if similar triggers such as validate_user, delete_user are required for a module it may be convenient to masquerade as a service. Ideally though, using the common structure improves the maintainability for other developers.
|
||||
|
||||
@@ -40,27 +42,31 @@ While this is the typical structure of the existing services modules, there is n
|
||||
|
||||
In order to integrate with Alliance Auth service modules must provide a `services_hook`. This hook will be a function that returns an instance of the `services.hooks.ServiceHook` class and decorated with the `@hooks.registerhook` decorator. For example:
|
||||
|
||||
@hooks.register('services_hook')
|
||||
def register_service():
|
||||
return ExampleService()
|
||||
```python
|
||||
@hooks.register('services_hook')
|
||||
def register_service():
|
||||
return ExampleService()
|
||||
```
|
||||
|
||||
This would register the ExampleService class which would need to be a subclass of `services.hooks.ServiceHook`.
|
||||
|
||||
:::{important}
|
||||
The hook **MUST** be registered in ``yourservice.auth_hooks`` along with any other hooks you are registering for Alliance Auth.
|
||||
The hook **MUST** be registered in ``yourservice.auth_hooks`` along with any other hooks you are registering for Alliance Auth.
|
||||
:::
|
||||
|
||||
A subclassed `ServiceHook` might look like this:
|
||||
|
||||
class ExampleService(ServicesHook):
|
||||
def __init__(self):
|
||||
ServicesHook.__init__(self)
|
||||
self.urlpatterns = urlpatterns
|
||||
self.service_url = 'http://exampleservice.example.com'
|
||||
```python
|
||||
class ExampleService(ServicesHook):
|
||||
def __init__(self):
|
||||
ServicesHook.__init__(self)
|
||||
self.urlpatterns = urlpatterns
|
||||
self.service_url = 'http://exampleservice.example.com'
|
||||
|
||||
"""
|
||||
Overload base methods here to implement functionality
|
||||
"""
|
||||
"""
|
||||
Overload base methods here to implement functionality
|
||||
"""
|
||||
```
|
||||
|
||||
### The ServiceHook class
|
||||
|
||||
@@ -70,9 +76,9 @@ You will need to subclass `services.hooks.ServiceHook` in order to provide imple
|
||||
|
||||
Instance Variables:
|
||||
|
||||
- [self.name](#self-name)
|
||||
- [self.urlpatterns](#self-url-patterns)
|
||||
- [self.service_ctrl_template](#self-service-ctrl-template)
|
||||
- [self.name](#selfname)
|
||||
- [self.urlpatterns](#selfurlpatterns)
|
||||
- [self.service_ctrl_template](#selfservice_ctrl_template)
|
||||
|
||||
Properties:
|
||||
|
||||
@@ -87,8 +93,6 @@ Functions:
|
||||
- [update_groups](#update_groups)
|
||||
- [update_groups_bulk](#update_groups_bulk)
|
||||
- [update_all_groups](#update_all_groups)
|
||||
- [service_enabled_members](#service_enabled_members)
|
||||
- [service_enabled_blues](#service_enabled_blues)
|
||||
- [service_active_for_user](#service_active_for_user)
|
||||
- [show_service_ctrl](#show_service_ctrl)
|
||||
- [render_service_ctrl](#render_service_ctrl)
|
||||
@@ -101,18 +105,20 @@ Internal name of the module, should be unique amongst modules.
|
||||
|
||||
You should define all of your service URLs internally, usually in `urls.py`. Then you can import them and set `self.urlpatterns` to your defined urlpatterns.
|
||||
|
||||
from . import urls
|
||||
...
|
||||
class MyService(ServiceHook):
|
||||
def __init__(self):
|
||||
...
|
||||
self.urlpatterns = urls.urlpatterns
|
||||
```python
|
||||
from . import urls
|
||||
...
|
||||
class MyService(ServiceHook):
|
||||
def __init__(self):
|
||||
...
|
||||
self.urlpatterns = urls.urlpatterns
|
||||
```
|
||||
|
||||
All of your apps defined urlpatterns will then be included in the `URLconf` when the core application starts.
|
||||
|
||||
#### self.service_ctrl_template
|
||||
|
||||
This is provided as a courtesy and defines the default template to be used with [render_service_ctrl](#render-service-ctrl). You are free to redefine or not use this variable at all.
|
||||
This is provided as a courtesy and defines the default template to be used with [render_service_ctrl](#render_service_ctrl). You are free to redefine or not use this variable at all.
|
||||
|
||||
#### title
|
||||
|
||||
@@ -134,10 +140,12 @@ Validate the users service account, deleting it if they should no longer have ac
|
||||
|
||||
An implementation will probably look like the following:
|
||||
|
||||
def validate_user(self, user):
|
||||
logger.debug('Validating user %s %s account' % (user, self.name))
|
||||
if ExampleTasks.has_account(user) and not self.service_active_for_user(user):
|
||||
self.delete_user(user, notify_user=True)
|
||||
```python
|
||||
def validate_user(self, user):
|
||||
logger.debug('Validating user %s %s account' % (user, self.name))
|
||||
if ExampleTasks.has_account(user) and not self.service_active_for_user(user):
|
||||
self.delete_user(user, notify_user=True)
|
||||
```
|
||||
|
||||
No return value is expected.
|
||||
|
||||
@@ -206,37 +214,39 @@ Should the service be shown for the given `user` with the given `state`? The `us
|
||||
|
||||
Usually you wont need to override this function.
|
||||
|
||||
For more information see the [render_service_ctrl](#render-service-ctrl) section.
|
||||
For more information see the [render_service_ctrl](#render_service_ctrl) section.
|
||||
|
||||
#### render_service_ctrl
|
||||
|
||||
`def render_services_ctrl(self, request):`
|
||||
|
||||
Render the services control row. This will be called for all active services when a user visits the `/services/` page and [show_service_ctrl](#show-service-ctrl) returns `True` for the given user.
|
||||
Render the services control row. This will be called for all active services when a user visits the `/services/` page and [show_service_ctrl](#show_service_ctrl) returns `True` for the given user.
|
||||
|
||||
It should return a string (usually from `render_to_string`) of a table row (`<tr>`) with 4 columns (`<td>`). Column #1 is the service name, column #2 is the users username for this service, column #3 is the services URL, and column #4 is the action buttons.
|
||||
|
||||
You may either define your own service template or use the default one provided. The default can be used like this example:
|
||||
|
||||
def render_services_ctrl(self, request):
|
||||
"""
|
||||
Example for rendering the service control panel row
|
||||
You can override the default template and create a
|
||||
custom one if you wish.
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
urls = self.Urls()
|
||||
urls.auth_activate = 'auth_example_activate'
|
||||
urls.auth_deactivate = 'auth_example_deactivate'
|
||||
urls.auth_reset_password = 'auth_example_reset_password'
|
||||
urls.auth_set_password = 'auth_example_set_password'
|
||||
return render_to_string(self.service_ctrl_template, {
|
||||
'service_name': self.title,
|
||||
'urls': urls,
|
||||
'service_url': self.service_url,
|
||||
'username': 'example username'
|
||||
}, request=request)
|
||||
```python
|
||||
def render_services_ctrl(self, request):
|
||||
"""
|
||||
Example for rendering the service control panel row
|
||||
You can override the default template and create a
|
||||
custom one if you wish.
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
urls = self.Urls()
|
||||
urls.auth_activate = 'auth_example_activate'
|
||||
urls.auth_deactivate = 'auth_example_deactivate'
|
||||
urls.auth_reset_password = 'auth_example_reset_password'
|
||||
urls.auth_set_password = 'auth_example_set_password'
|
||||
return render_to_string(self.service_ctrl_template, {
|
||||
'service_name': self.title,
|
||||
'urls': urls,
|
||||
'service_url': self.service_url,
|
||||
'username': 'example username'
|
||||
}, request=request)
|
||||
```
|
||||
|
||||
the `Urls` class defines the available URL names for the 4 actions available in the default template:
|
||||
|
||||
@@ -293,3 +303,9 @@ You should have a look through some of the other service modules before you get
|
||||
## Testing
|
||||
|
||||
You will need to add unit tests for all aspects of your service module before it is accepted. Be mindful that you don't actually want to make external calls to the service so you should mock the appropriate components to prevent this behavior.
|
||||
|
||||
```{eval-rst}
|
||||
.. autoclass:: allianceauth.services.hooks.ServicesHook
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# Logging from Custom Apps
|
||||
|
||||
Alliance Auth provides a logger for use with custom apps to make everyone's life a little easier.
|
||||
|
||||
## Using the Extensions Logger
|
||||
|
||||
AllianceAuth provides a helper function to get the logger for the current module to reduce the amount of
|
||||
code you need to write.
|
||||
|
||||
@@ -15,19 +17,28 @@ This works by creating a child logger of the extension logger which propagates a
|
||||
to the parent (extensions) logger.
|
||||
|
||||
## Changing the Logging Level
|
||||
|
||||
By default, the extension logger's level is set to `DEBUG`.
|
||||
To change this, uncomment (or add) the following line in `local.py`.
|
||||
|
||||
```python
|
||||
LOGGING['handlers']['extension_file']['level'] = 'INFO'
|
||||
```
|
||||
|
||||
*(Remember to restart your supervisor workers after changes to `local.py`)*
|
||||
|
||||
This will change the logger's level to the level you define.
|
||||
|
||||
Options are: *(all options accept entries of levels listed below them)*
|
||||
|
||||
* `DEBUG`
|
||||
* `INFO`
|
||||
* `WARNING`
|
||||
* `ERROR`
|
||||
* `CRITICAL`
|
||||
|
||||
```{eval-rst}
|
||||
.. automodule:: allianceauth.services.hooks.get_extension_logger
|
||||
:members:
|
||||
:undoc-members:
|
||||
```
|
||||
|
||||
@@ -4,10 +4,10 @@ The menu hooks allow you to dynamically specify menu items from your plugin app
|
||||
|
||||
To register a MenuItemHook class you would do the following:
|
||||
|
||||
```Python
|
||||
```python
|
||||
@hooks.register('menu_item_hook')
|
||||
def register_menu():
|
||||
return MenuItemHook('Example Item', 'glyphicon glyphicon-heart', 'example_url_name',150)
|
||||
return MenuItemHook('Example Item', 'fas fa-users fa-fw', 'example_url_name',150)
|
||||
```
|
||||
|
||||
The `MenuItemHook` class specifies some parameters/instance variables required for menu item display.
|
||||
@@ -41,13 +41,14 @@ A list of views or namespaces the link should be highlighted on. See [django-nav
|
||||
This is a great feature to signal the user, that he has some open issues to take care of within an app. For example Auth uses this feature to show the specific number of open group request to the current user.
|
||||
|
||||
:::{hint}
|
||||
Here is how to stay consistent with the Auth design philosophy for using this feature:
|
||||
1. Use it to display open items that the current user can close by himself only. Do not use it for items, that the user has no control over.
|
||||
2. If there are currently no open items, do not show a badge at all.
|
||||
Here is how to stay consistent with the Auth design philosophy for using this feature:
|
||||
|
||||
1. Use it to display open items that the current user can close by himself only. Do not use it for items, that the user has no control over.
|
||||
2. If there are currently no open items, do not show a badge at all.
|
||||
:::
|
||||
To use it set count the `render()` function of your subclass in accordance to the current user. Here is an example:
|
||||
|
||||
```Python
|
||||
```python
|
||||
def render(self, request):
|
||||
# ...
|
||||
self.count = calculate_count_for_user(request.user)
|
||||
|
||||
@@ -19,8 +19,8 @@ In addition is it possible to make views public. Normally, all views are automat
|
||||
An app can opt-out of this feature by adding a list of views to be excluded when registering the URLs. See the `excluded_views` parameter for details.
|
||||
|
||||
:::{note}
|
||||
Note that for a public view to work, administrators need to also explicitly allow apps to have public views in their AA installation, by adding the apps label to ``APPS_WITH_PUBLIC_VIEWS`` setting.
|
||||
```
|
||||
Note that for a public view to work, administrators need to also explicitly allow apps to have public views in their AA installation, by adding the apps label to ``APPS_WITH_PUBLIC_VIEWS`` setting.
|
||||
:::
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ The main benefit of this setup is that it runs all services and code in the nati
|
||||
In addition all tools described in this guide are open source or free software.
|
||||
|
||||
:::{hint}
|
||||
This guide is meant for development purposes only and not for installing AA in a production environment. For production installation please see chapter **Installation**.
|
||||
This guide is meant for development purposes only and not for installing AA in a production environment. For production installation please see chapter **Installation**.
|
||||
:::
|
||||
|
||||
## Overview
|
||||
@@ -25,8 +25,8 @@ The development environment consists of the following components:
|
||||
We will use the build-in Django development web server, so we don't need to setup a WSGI server or a web server.
|
||||
|
||||
:::{note}
|
||||
This setup works with both WSL 1 and WSL 2. However, due to the significantly better performance we recommend WSL 2.
|
||||
```
|
||||
This setup works with both WSL 1 and WSL 2. However, due to the significantly better performance we recommend WSL 2.
|
||||
:::
|
||||
|
||||
## Requirement
|
||||
|
||||
@@ -37,19 +37,14 @@ The only requirement is a PC with Windows 10 and Internet connection in order to
|
||||
### Windows Subsystem for Linux
|
||||
|
||||
- Install from here: [Microsoft docs](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
|
||||
|
||||
- Choose Ubuntu 18.04. LTS or higher
|
||||
|
||||
### Visual Studio Code
|
||||
|
||||
- Install from here: [VSC Download](https://code.visualstudio.com/Download)
|
||||
|
||||
- Open the app and install the following VSC extensions:
|
||||
|
||||
- Remote WSL
|
||||
|
||||
- Connect to WSL. This will automatically install the VSC server on the VSC server for WSL
|
||||
|
||||
- Once connected to WSL install the Python extension on the WSL side
|
||||
|
||||
## Setting up WSL / Linux
|
||||
@@ -71,18 +66,18 @@ sudo apt-get install gettext
|
||||
|
||||
Next we need to install Python and related development tools.
|
||||
|
||||
:::{hint}
|
||||
:::
|
||||
|
||||
:::{note}
|
||||
Should your Ubuntu come with a newer version of Python we recommend to still setup your dev environment with the oldest Python 3 version currently supported by AA (e.g Python 3.8 at this time of writing) to ensure your apps are compatible with all current AA installations
|
||||
You an check out this `page <https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get/1195153>`_ on how to install additional Python versions on Ubuntu.
|
||||
Should your Ubuntu come with a newer version of Python we recommend to still setup your dev environment with the oldest Python 3 version currently supported by AA (e.g Python 3.8 at this time of writing) to ensure your apps are compatible with all current AA installations
|
||||
You an check out this `page <https://askubuntu.com/questions/682869/how-do-i-install-a-different-python-version-using-apt-get/1195153>`_ on how to install additional Python versions on Ubuntu.
|
||||
|
||||
If you install a different python version from the default you need to adjust some of the commands below to install appopriate versions of those packages for example using Python 3.8 you might need to run the following after using the setup steps for the repository mentioned in the AskUbuntu post above:
|
||||
If you install a different python version from the default you need to adjust some of the commands below to install appopriate versions of those packages for example using Python 3.8 you might need to run the following after using the setup steps for the repository mentioned in the AskUbuntu post above:
|
||||
|
||||
`sudo apt-get install python3.8 python3.8-dev python3.8-venv python3-setuptools python3-pip python-pip`
|
||||
```shell
|
||||
sudo apt-get install python3.8 python3.8-dev python3.8-venv python3-setuptools python3-pip python-pip
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
Use the following command to install Python 3 with all required libraries with the default version:
|
||||
|
||||
```shell
|
||||
@@ -110,8 +105,8 @@ sudo apt-get install mysql-server mysql-client libmysqlclient-dev
|
||||
```
|
||||
|
||||
:::{note}
|
||||
We chose to use MySQL instead of MariaDB, because the standard version of MariaDB that comes with this Ubuntu distribution will not work with AA.
|
||||
```
|
||||
We chose to use MySQL instead of MariaDB, because the standard version of MariaDB that comes with this Ubuntu distribution will not work with AA.
|
||||
:::
|
||||
|
||||
We need to apply a permission fix to mysql or you will get a warning with every startup:
|
||||
|
||||
@@ -146,17 +141,17 @@ sudo mysql_tzinfo_to_sql /usr/share/zoneinfo | sudo mysql -u root mysql
|
||||
```
|
||||
|
||||
:::{note}
|
||||
If your WSL does not have an init.d service, it will not automatically start your services such as MySQL and Redis when you boot your Windows machine and you have to manually start them. For convenience we recommend putting these commands in a bash script. Here is an example:
|
||||
|
||||
::
|
||||
|
||||
#/bin/bash
|
||||
# start services for AA dev
|
||||
sudo service mysql start
|
||||
sudo redis-server --daemonize yes
|
||||
If your WSL does not have an init.d service, it will not automatically start your services such as MySQL and Redis when you boot your Windows machine and you have to manually start them. For convenience we recommend putting these commands in a bash script. Here is an example:
|
||||
|
||||
```shell
|
||||
#/bin/bash
|
||||
# start services for AA dev
|
||||
sudo service mysql start
|
||||
sudo redis-server --daemonize yes
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
### Setup dev folder on WSL
|
||||
|
||||
Setup your folders on WSL bash for your dev project. Our approach will setup one AA project with one venv and multiple apps running under the same AA project, but each in their own folder and git.
|
||||
@@ -177,7 +172,7 @@ Following this approach you can also setup additional AA projects, e.g. aa-dev-2
|
||||
Create the root folder `aa-dev`.
|
||||
|
||||
:::{hint}
|
||||
The folders `venv` and `myauth` will be created automatically in later steps. Please do not create them manually as this would lead to errors.
|
||||
The folders `venv` and `myauth` will be created automatically in later steps. Please do not create them manually as this would lead to errors.
|
||||
:::
|
||||
|
||||
### Setup virtual Python environment for aa-dev
|
||||
@@ -237,7 +232,7 @@ For the Eve Online related setup you need to create a SSO app on the developer s
|
||||
Open your local Django settings with VSC. The file is under `myauth/myauth/settings/local.py`
|
||||
|
||||
:::{hint}
|
||||
There are two Django settings files: ``base.py`` and ``local.py``. The base settings file is controlled by the AA project and may change at any time. It is therefore recommended to only change the local settings file.
|
||||
There are two Django settings files: ``base.py`` and ``local.py``. The base settings file is controlled by the AA project and may change at any time. It is therefore recommended to only change the local settings file.
|
||||
:::
|
||||
|
||||
```python
|
||||
@@ -308,15 +303,15 @@ python manage.py runserver
|
||||
Once running you can access your auth site on the browser under `http://localhost:8000`. Or the admin site under `http://localhost:8000/admin`
|
||||
|
||||
:::{hint}
|
||||
You can start your AA server directly from a terminal window in VSC or with a VSC debug config (see chapter about debugging for details).
|
||||
You can start your AA server directly from a terminal window in VSC or with a VSC debug config (see chapter about debugging for details).
|
||||
:::
|
||||
|
||||
:::{note}
|
||||
**Debug vs. Non-Debug mode**
|
||||
Usually it is best to run your dev AA instance in debug mode, so you get all the detailed error messages that helps a lot for finding errors. But there might be cases where you want to test features that do not exist in debug mode (e.g. error pages) or just want to see how your app behaves in non-debug / production mode.
|
||||
**Debug vs. Non-Debug mode**
|
||||
Usually it is best to run your dev AA instance in debug mode, so you get all the detailed error messages that helps a lot for finding errors. But there might be cases where you want to test features that do not exist in debug mode (e.g. error pages) or just want to see how your app behaves in non-debug / production mode.
|
||||
|
||||
When you turn off debug mode you will see a problem though: Your pages will not render correctly. The reason is that Django will stop serving your static files in production mode and expect you to serve them from a real web server. Luckily, there is an option that forces Django to continue serving your static files directly even when not in debug mode. Just start your server with the following option: ``python manage.py runserver --insecure``
|
||||
```
|
||||
When you turn off debug mode you will see a problem though: Your pages will not render correctly. The reason is that Django will stop serving your static files in production mode and expect you to serve them from a real web server. Luckily, there is an option that forces Django to continue serving your static files directly even when not in debug mode. Just start your server with the following option: ``python manage.py runserver --insecure``
|
||||
:::
|
||||
|
||||
### Celery
|
||||
|
||||
|
||||
@@ -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