1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

31 lines
1.3 KiB
Markdown
Raw Normal View History

2022-01-25 13:53:31 -05:00
# Background Tasks
2022-03-08 14:15:22 -05:00
NetBox supports the queuing of tasks that need to be performed in the background, decoupled from the request-response cycle, using the [Python RQ](https://python-rq.org/) library. Three task queues of differing priority are defined by default:
2022-01-25 13:53:31 -05:00
2022-03-08 14:15:22 -05:00
* High
* Default
* Low
Any tasks in the "high" queue are completed before the default queue is checked, and any tasks in the default queue are completed before those in the "low" queue.
Plugins can also add custom queues for their own needs by setting the `queues` attribute under the PluginConfig class. An example is included below:
2022-01-25 13:53:31 -05:00
```python
class MyPluginConfig(PluginConfig):
name = 'myplugin'
...
queues = [
2022-03-08 14:15:22 -05:00
'foo',
'bar',
2022-01-25 13:53:31 -05:00
]
```
2022-03-08 14:15:22 -05:00
The PluginConfig above creates two custom queues with the following names `my_plugin.foo` and `my_plugin.bar`. (The plugin's name is prepended to each queue to avoid conflicts between plugins.)
2022-01-25 13:53:31 -05:00
2022-03-08 14:15:22 -05:00
!!! warning "Configuring the RQ worker process"
By default, NetBox's RQ worker process only services the high, default, and low queues. Plugins which introduce custom queues should advise users to either reconfigure the default worker, or run a dedicated worker specifying the necessary queues. For example:
```
python manage.py rqworker my_plugin.foo my_plugin.bar
```