From dce3e0763fcd94e687c72c2b68df0db4bebca3f5 Mon Sep 17 00:00:00 2001 From: maximumG Date: Fri, 9 Jul 2021 09:42:03 +0200 Subject: [PATCH] chore: documentation about netbox plugin queueing system --- docs/plugins/development.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/plugins/development.md b/docs/plugins/development.md index f008da2fb..7aab5ca8a 100644 --- a/docs/plugins/development.md +++ b/docs/plugins/development.md @@ -413,3 +413,31 @@ caching_config = { ``` See the [django-cacheops](https://github.com/Suor/django-cacheops) documentation for more detail on configuring caching. + +## Background Tasks + +By default, Netbox provides 3 differents [RQ](https://python-rq.org/) queues to run background jobs : *high*, *default* and *low*. +These 3 core queues can be used out-of-the-box by plugins to define background tasks. + +Plugins can also define dedicated queues. These queues can be configured under the PluginConfig class `queues` attribute. An example configuration +is below: + +```python +class MyPluginConfig(PluginConfig): + name = 'myplugin' + ... + queues = [ + 'queue1', + 'queue2', + 'queue-whatever-the-name' + ] +``` + +The PluginConfig above creates 3 queues with the following names: *myplugin.queue1*, *myplugin.queue2*, *myplugin.queue-whatever-the-name*. +As you can see, the queue's name is always preprended with the plugin's name, to avoid any name clashes between different plugins. + +In case you create dedicated queues for your plugin, it is strongly advised to also create a dedicated RQ worker instance. This instance should only listen to the queues defined in your plugin - to avoid impact between your background tasks and netbox internal tasks. + +``` +python manage.py rqworker myplugin.queue1 myplugin.queue2 myplugin.queue-whatever-the-name +``` \ No newline at end of file