Skip to content

Commit 9ebdd39

Browse files
committed
Improve Readme
1 parent a14cdf7 commit 9ebdd39

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

README.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22

33
DLQ is a lightweight & modular queue and cron system for Django.
44

5+
## Installation
6+
7+
```shell
8+
pip install django-lightweight-queue[redis]
9+
```
10+
11+
Currently the only production-ready backends are redis-based, so the `redis`
12+
extra is essentially required. Additional non-redis backed production-ready
13+
backends are great candidates for community contributions.
14+
515
## Basic Usage
616

7-
``` python
17+
```python
818
import time
919
from django_lightweight_queue import task
1020

@@ -25,42 +35,50 @@ for more details.
2535
All automatically picked up configuration options begin with `LIGHTWEIGHT_QUEUE_`
2636
and can be found in `app_settings.py`. They should be placed in the usual Django
2737
settings files, for example:
28-
``` python
38+
39+
```python
2940
LIGHTWEIGHT_QUEUE_BACKEND = 'django_lightweight_queue.backends.redis.RedisBackend'
3041
```
3142

32-
If desired, specific configuration overrides can be placed in a standalone python
33-
file which passed on the command line.
43+
#### Special Configuration
44+
45+
If desired, specific configuration overrides can be placed in a standalone
46+
python file which passed on the command line. This is useful for applying
47+
customisations for specific servers.
3448

3549
For example, given a `special.py` containing:
36-
``` python
50+
51+
```python
3752
LIGHTWEIGHT_QUEUE_REDIS_PORT = 12345
3853
```
54+
3955
and then running:
56+
4057
```
4158
$ python manage.py queue_runner --config=special.py
4259
```
60+
4361
will result in the runner to use the settings from the specified configuration
4462
file in preference to settings from the Django environment. Any settings not
4563
present in the specified file are inherited from the global configuration.
4664

4765
### Backends
4866

4967
There are four built-in backends:
50-
- Synchronous (the default): executes the task inline, without any actual queuing
51-
- Redis: executes tasks at-most-once using [Redis][redis] for storage of the
52-
enqueued tasks
53-
- Reliable Redis: executes tasks at-least-once using [Redis][redis] for storage
54-
of the enqueued tasks
55-
- Debug Web: a backend for use in debugging. Instead of running jobs it prints
56-
the url to a view that can be used to run a task in a transaction which will
57-
be rolled back. This is useful for debugging and optimising tasks.
68+
69+
| Backend | Type | Description |
70+
| -------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
71+
| Synchronous | Development | Executes the task inline, without any actual queuing. |
72+
| Redis | Production | Executes tasks at-most-once using [Redis][redis] for storage of the enqueued tasks. |
73+
| Reliable Redis | Production | Executes tasks at-least-once using [Redis][redis] for storage of the enqueued tasks (subject to Redis consistency). Does not guarantee the task _completes_. |
74+
| Debug Web | Debugging | Instead of running jobs it prints the url to a view that can be used to run a task in a transaction which will be rolled back. This is useful for debugging and optimising tasks. |
5875

5976
[redis]: https://redis.io/
6077

6178
## Running Workers
6279

6380
The queue runner is implemented as a Django management command:
81+
6482
```
6583
$ python manage.py queue_runner
6684
```
@@ -73,37 +91,47 @@ $ python manage.py queue_runner --machine 2 --of 4
7391
```
7492

7593
Alternatively a runner can be told explicitly which configuration to use:
94+
7695
```
7796
$ python manage.py queue_runner --exact-configuration --config=special.py
7897
```
98+
7999
When using `--exact-configuration` the number of workers is configured exactly,
80100
rather than being treated as the configuration for a pool. Additionally,
81101
exactly-configured runners will _not_ run any cron workers.
82102

83103
### Example
84104

85105
Given a Django configuration containing:
86-
``` python
106+
107+
```python
87108
LIGHTWEIGHT_QUEUE_WORKERS = {
88109
'queue1': 3,
89110
}
90111
```
112+
91113
and a `special.py` containing:
92-
``` python
114+
115+
```python
93116
LIGHTWEIGHT_QUEUE_WORKERS = {
94117
'queue1': 2,
95118
}
96119
```
120+
97121
Running any of:
122+
98123
```
99124
$ python manage.py queue_runner --machine 1 --of 3 # or,
100125
$ python manage.py queue_runner --machine 2 --of 3 # or,
101126
$ python manage.py queue_runner --machine 3 --of 3
102127
```
128+
103129
will result in one worker for `queue1` on the current machine, while:
130+
104131
```
105132
$ python manage.py queue_runner --exact-configuration --config=special.py
106133
```
134+
107135
will result in two workers on the current machine.
108136

109137
## Cron Tasks
@@ -115,7 +143,7 @@ To specify that a management command should be run at a given time, place a
115143
`cron.py` file in the root folder of the Django app which defines the command
116144
and which contains a `CONFIG` variable:
117145

118-
``` python
146+
```python
119147
CONFIG = (
120148
{
121149
'command': 'my_cron_command',

0 commit comments

Comments
 (0)