An app that provides django integration for RQ (Redis Queue)
npx @tessl/cli install tessl/pypi-django-rq@3.1.00
# Django-RQ
1
2
Django integration for RQ (Redis Queue), a Python library for queueing jobs and processing them in the background with workers. Django-RQ provides seamless integration with Django's settings system, management commands for running workers, a web-based dashboard for monitoring queue status, and optional integrations with monitoring tools.
3
4
## Package Information
5
6
- **Package Name**: django-rq
7
- **Language**: Python
8
- **Installation**: `pip install django-rq`
9
10
## Core Imports
11
12
```python
13
import django_rq
14
```
15
16
For job decoration:
17
```python
18
from django_rq import job
19
```
20
21
For queue and worker management:
22
```python
23
from django_rq import get_queue, get_worker, get_connection, get_scheduler
24
```
25
26
## Basic Usage
27
28
```python
29
import django_rq
30
from django_rq import job
31
32
# Basic job enqueueing
33
def my_task(arg1, arg2):
34
return arg1 + arg2
35
36
# Enqueue job to default queue
37
django_rq.enqueue(my_task, 10, 20)
38
39
# Using @job decorator
40
@job
41
def decorated_task():
42
return "Hello from RQ!"
43
44
# Queue job using decorator
45
decorated_task.delay()
46
47
# Working with specific queues
48
queue = django_rq.get_queue('high')
49
queue.enqueue(my_task, 5, 15)
50
51
# Creating workers
52
worker = django_rq.get_worker('default', 'high')
53
worker.work(burst=True)
54
```
55
56
## Architecture
57
58
Django-RQ extends RQ's core components with Django-specific features:
59
60
- **DjangoRQ Queue**: Extended Queue class with Django settings integration and autocommit support
61
- **Management Commands**: Django commands for worker management (rqworker, rqscheduler, etc.)
62
- **Web Dashboard**: Admin interface for monitoring queues, jobs, and workers
63
- **Settings Integration**: Configuration through Django's settings.py file
64
- **Prometheus Metrics**: Optional monitoring integration
65
- **Template Tags**: Django template helpers for displaying job information
66
67
## Capabilities
68
69
### Job Management
70
71
Core functionality for creating, enqueueing, and managing background jobs including job decoration, queue operations, and worker management.
72
73
```python { .api }
74
def enqueue(func, *args, **kwargs):
75
"""Enqueue a job to the default queue."""
76
77
@job
78
def decorated_function():
79
"""Decorator to create RQ tasks."""
80
81
def get_queue(name='default', **kwargs):
82
"""Get a queue instance by name."""
83
84
def get_worker(*queue_names, **kwargs):
85
"""Get a worker instance for specified queues."""
86
```
87
88
[Job Management](./job-management.md)
89
90
### Queue Operations
91
92
Queue creation, configuration, and management including multiple queue support, Redis connection handling, and queue statistics.
93
94
```python { .api }
95
def get_connection(name='default', use_strict_redis=False):
96
"""Get Redis connection for a queue."""
97
98
def get_queues(*queue_names, **kwargs):
99
"""Get multiple queue instances."""
100
101
class DjangoRQ:
102
"""Django-specific Queue class with autocommit support."""
103
def enqueue_call(self, *args, **kwargs): ...
104
```
105
106
[Queue Operations](./queue-operations.md)
107
108
### Scheduling
109
110
Job scheduling functionality including delayed execution, periodic tasks, and scheduler management.
111
112
```python { .api }
113
def get_scheduler(name='default', **kwargs):
114
"""Get scheduler instance for delayed/periodic jobs."""
115
116
class DjangoScheduler:
117
"""Django-specific Scheduler class."""
118
def _create_job(self, *args, **kwargs): ...
119
```
120
121
[Scheduling](./scheduling.md)
122
123
### Management Commands
124
125
Django management commands for worker control, queue monitoring, and system maintenance.
126
127
```python { .api }
128
# Management commands (via manage.py)
129
# python manage.py rqworker [queues...]
130
# python manage.py rqscheduler
131
# python manage.py rqstats
132
# python manage.py rqsuspend
133
# python manage.py rqresume
134
```
135
136
[Management Commands](./management-commands.md)
137
138
### Web Dashboard
139
140
Web-based monitoring interface for queues, jobs, workers, and statistics with Django admin integration.
141
142
```python { .api }
143
# URL patterns for web interface
144
urlpatterns = [
145
path('django-rq/', include('django_rq.urls'))
146
]
147
```
148
149
[Web Dashboard](./web-dashboard.md)
150
151
### Monitoring & Integration
152
153
Prometheus metrics collection, Sentry integration, and Django-specific monitoring features.
154
155
```python { .api }
156
from django_rq.utils import get_statistics, configure_sentry
157
from django_rq.contrib.prometheus import RQCollector
158
```
159
160
[Monitoring & Integration](./monitoring-integration.md)
161
162
## Configuration
163
164
Django-RQ is configured through Django settings:
165
166
```python { .api }
167
# settings.py
168
RQ_QUEUES = {
169
'default': {
170
'HOST': 'localhost',
171
'PORT': 6379,
172
'DB': 0,
173
},
174
'high': {
175
'HOST': 'localhost',
176
'PORT': 6379,
177
'DB': 0,
178
}
179
}
180
181
# Optional settings
182
RQ = {
183
'DEFAULT_RESULT_TTL': 500,
184
'AUTOCOMMIT': True,
185
}
186
```