@@ -12,11 +12,11 @@ Tested against Django 1.8, 1.9, 1.10, 1.11
1212## Getting Started
1313
1414### Installation
15-
15+
1616Install from PIP
17-
17+
1818 pip install django-db-queue
19-
19+
2020Add ` 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
54101In another terminal:
0 commit comments