Skip to content

Commit 32b1ac9

Browse files
committed
Add notes on pre/post hook behaviour
1 parent c52941f commit 32b1ac9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ JOBS = {
113113
```
114114

115115
#### Pre & Post Task Hooks
116-
You can also run pre task or post task hooks, which happen in the normal processing of your `Job` instances and are executed in the worker process.
116+
You can also run pre task or post task hooks, which happen in the normal processing of your `Job` instances and are executed inside the worker process.
117117

118118
Both pre and post task hooks receive your `Job` instance as their only argument. Here's an example:
119119

@@ -122,7 +122,7 @@ def my_pre_task_hook(job):
122122
... # configure something before running your task
123123
```
124124

125-
To ensure these hooks gets run, simply add a `pre_task_hook` or `post_task_hook` key (or both, if needed) to your job config like so:
125+
To ensure these hooks are run, simply add a `pre_task_hook` or `post_task_hook` key (or both, if needed) to your job config like so:
126126

127127
```python
128128
JOBS = {
@@ -134,6 +134,12 @@ JOBS = {
134134
}
135135
```
136136

137+
Notes:
138+
139+
* If the `pre_task_hook` fails (raises an exception), the task function is not run, and django-db-queue behaves as if the task function itself had failed: the failure hook is called, and the job is goes into the `FAILED` state.
140+
* The `post_task_hook` is always run, even if the job fails. In this case, it runs after the `failure_hook`.
141+
* If the `post_task_hook` raises an exception, this is logged but the the job is **not marked as failed** and the failure hook does not run. This is because the `post_task_hook` might need to perform cleanup that always happens after the task, no matter whether it succeeds or fails.
142+
137143

138144
### Start the worker
139145

0 commit comments

Comments
 (0)