Skip to content

Commit 6453882

Browse files
committed
Document hooks in readme
1 parent f676571 commit 6453882

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

README.md

Lines changed: 49 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,52 @@ 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.
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 are run just before a job begins.
79+
80+
A creation hook receives your `Job` instance as its only argument. Here's an example:
81+
82+
```python
83+
def my_task_creation_hook(job):
84+
# configure something before running your job
85+
```
86+
87+
To ensure this hook gets run, simply add a `creation_hook` key to your job config like so:
88+
89+
```python
90+
JOBS = {
91+
'my_job': {
92+
'tasks': ['project.common.jobs.my_task'],
93+
'creation_hook': 'project.common.jobs.my_task_creation_hook'
94+
},
95+
}
96+
```
97+
5298
### Start the worker
5399

54100
In another terminal:

0 commit comments

Comments
 (0)