Document_stopped_jobs and dependents for enqueue_many (#1922)

* Add documentation for on_stopped callback

* Update dependent jobs documentation

Starting in version 1.15.0, enqueue_many supports dependent jobs.

* Add stopped callback usage example

* Update callback docstring

* Fix arg type

* Remove trailing whitespace
main
Ethan Wolinsky 2 years ago committed by GitHub
parent 4011186c35
commit 6fdadaabe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -131,8 +131,7 @@ with q.connection.pipeline() as pipe:
pipe.execute() pipe.execute()
``` ```
`Queue.prepare_data` accepts all arguments that `Queue.parse_args` does **EXCEPT** for `depends_on`, `Queue.prepare_data` accepts all arguments that `Queue.parse_args` does.
which is not supported at this time, so dependencies will be up to you to setup.
## Job dependencies ## Job dependencies
@ -195,18 +194,18 @@ job_2 = queue.enqueue(say_hello, depends_on=dependency)
## Job Callbacks ## Job Callbacks
_New in version 1.9.0._ _New in version 1.9.0._
If you want to execute a function whenever a job completes or fails, RQ provides If you want to execute a function whenever a job completes, fails, or is stopped, RQ provides
`on_success` and `on_failure` callbacks. `on_success`, `on_failure`, and `on_stopped` callbacks.
```python ```python
queue.enqueue(say_hello, on_success=report_success, on_failure=report_failure) queue.enqueue(say_hello, on_success=report_success, on_failure=report_failure, on_stopped=report_stopped)
``` ```
### Callback Class and Callback Timeouts ### Callback Class and Callback Timeouts
_New in version 1.14.0_ _New in version 1.14.0_
RQ lets you configure the method and timeout for each callback - success and failure. RQ lets you configure the method and timeout for each callback - success, failure, and stopped.
To configure callback timeouts, use RQ's To configure callback timeouts, use RQ's
`Callback` object that accepts `func` and `timeout` arguments. For example: `Callback` object that accepts `func` and `timeout` arguments. For example:
@ -214,7 +213,8 @@ To configure callback timeouts, use RQ's
from rq import Callback from rq import Callback
queue.enqueue(say_hello, queue.enqueue(say_hello,
on_success=Callback(report_success), # default callback timeout (60 seconds) on_success=Callback(report_success), # default callback timeout (60 seconds)
on_failure=Callback(report_failure, timeout=10)) # 10 seconds timeout on_failure=Callback(report_failure, timeout=10), # 10 seconds timeout
on_stopped=Callback(report_stopped, timeout="2m")) # 2 minute timeout
``` ```
### Success Callback ### Success Callback
@ -249,6 +249,19 @@ def report_failure(job, connection, type, value, traceback):
Failure callbacks are limited to 60 seconds of execution time. Failure callbacks are limited to 60 seconds of execution time.
### Stopped Callbacks
Stopped callbacks are functions that accept `job` and `connection` arguments.
```python
def report_stopped(job, connection):
pass
```
Stopped callbacks are functions that are executed when a worker receives a command to stop
a job that is currently executing. See [Stopping a Job](https://python-rq.org/docs/workers/#stopping-a-job).
### CLI Enqueueing ### CLI Enqueueing
_New in version 1.10.0._ _New in version 1.10.0._

@ -71,8 +71,8 @@ in seconds. Defaults to 10 minutes.
CALLBACK_TIMEOUT = 60 CALLBACK_TIMEOUT = 60
""" The timeout period in seconds for Callback functions """ The timeout period in seconds for Callback functions
Means that Functions used in `success_callback` and `failure_callback` Means that Functions used in `success_callback`, `stopped_callback`,
will timeout after N seconds and `failure_callback` will timeout after N seconds
""" """

Loading…
Cancel
Save