Skip to content

Commit 083a05e

Browse files
authored
Merge branch 'master' into priority-queueing
2 parents 544ee21 + ddf9450 commit 083a05e

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Tested against Django 1.8, 1.9, 1.10, 1.11
1212
## Getting Started
1313

1414
### Installation
15-
15+
1616
Install from PIP
17-
17+
1818
pip install django-db-queue
19-
19+
2020
Add `django_dbq` to your installed apps
2121

2222
INSTALLED_APPS = (
@@ -49,6 +49,53 @@ JOBS = {
4949
}
5050
```
5151

52+
### Hooks
53+
54+
55+
#### Failure Hooks
56+
When an unhandled exception is raised by a job, a failure hook will be called if one exists enabling
57+
you to clean up any state left behind by your failed job. Failure hooks are run in your worker process (if your job fails).
58+
59+
A failure hook receives the failed `Job` instance along with the unhandled exception raised by your failed job as its arguments. Here's an example:
60+
61+
```python
62+
def my_task_failure_hook(job, e):
63+
# delete some temporary files on the filesystem
64+
```
65+
66+
To ensure this hook gets run, simply add a `failure_hook` key to your job config like so:
67+
68+
```python
69+
JOBS = {
70+
'my_job': {
71+
'tasks': ['project.common.jobs.my_task'],
72+
'failure_hook': 'project.common.jobs.my_task_failure_hook'
73+
},
74+
}
75+
```
76+
77+
#### Creation Hooks
78+
You can also run creation hooks, which happen just after the creation of your `Job` instances and are executed in the process
79+
in which the job was created, _not the worker process_.
80+
81+
A creation hook receives your `Job` instance as its only argument. Here's an example:
82+
83+
```python
84+
def my_task_creation_hook(job):
85+
# configure something before running your job
86+
```
87+
88+
To ensure this hook gets run, simply add a `creation_hook` key to your job config like so:
89+
90+
```python
91+
JOBS = {
92+
'my_job': {
93+
'tasks': ['project.common.jobs.my_task'],
94+
'creation_hook': 'project.common.jobs.my_task_creation_hook'
95+
},
96+
}
97+
```
98+
5299
### Start the worker
53100

54101
In another terminal:
@@ -141,3 +188,7 @@ To start a worker:
141188
## Testing
142189

143190
It may be necessary to supply a DATABASE_PORT environment variable.
191+
192+
## Code of conduct
193+
194+
For guidelines regarding the code of conduct when contributing to this repository please review [https://www.dabapps.com/open-source/code-of-conduct/](https://www.dabapps.com/open-source/code-of-conduct/)

0 commit comments

Comments
 (0)