1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# Django Tasks RQ
[](https://github.com/RealOrangeOne/django-tasks-rq/actions/workflows/ci.yml)




A [Django Tasks](https://docs.djangoproject.com/en/stable/topics/tasks/) backend which uses RQ as its underlying queue.
## Installation
```
python -m pip install django-tasks
```
First, add `django_tasks_rq` to your `INSTALLED_APPS`:
```python
INSTALLED_APPS = [
# ...
"django_tasks_rq",
]
```
Finally, add it to your `TASKS` configuration:
```python
TASKS = {
"default": {
"BACKEND": "django_tasks_rq.RQBackend",
"QUEUES": ["default"]
}
}
```
## Usage
The RQ-based backend acts as an interface between [Django's tasks interface](https://docs.djangoproject.com/en/stable/topics/tasks/) and `RQ`, allowing tasks to be defined and enqueued using `django.tasks`, but stored in Redis and executed using RQ's workers.
Any queues defined in `QUEUES` must also be defined in `django-rq`'s `RQ_QUEUES` setting.
### Job class
To use `rq` with `django-tasks-rq`, a custom `Job` class must be used. This can be passed to the worker using `--job-class`:
```shell
./manage.py rqworker --job-class django_tasks_rq.Job
```
### Priorities
`rq` has no native concept of priorities - instead relying on workers to define which queues they should pop tasks from in order. Therefore, `task.priority` has little effect on execution priority.
If a task has a priority of `100`, it is enqueued at the top of the queue, and will be the next task executed by a worker. All other priorities will enqueue the task to the back of the queue. The queue value is not stored, and will always be `0`.
## Contributing
See [CONTRIBUTING.md](./CONTRIBUTING.md) for information on how to contribute.
Note: Prior to `0.12.0`, this backend was included in [`django-tasks`](https://github.com/RealOrangeOne/django-tasks/). Whilst the commit history was cleaned up, it's still quite messy. Don't look too closely.
|