summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelwin Ong <selwin.ong@gmail.com>2020-07-13 20:11:37 +0700
committerSelwin Ong <selwin.ong@gmail.com>2020-07-13 20:11:37 +0700
commit9b414681c9e2b1ba9a1ce6393102479730b573bc (patch)
treed461ed28571a5322c7334fd67ecdd087b3059375
parent29cfa2d8f79551b8cc1bf9de8909174b764a2d9e (diff)
downloadrq-retry.tar.gz
Added docs for job retriesretry
-rw-r--r--docs/_config.yml6
-rw-r--r--docs/docs/exceptions.md57
-rw-r--r--docs/docs/scheduling.md4
3 files changed, 57 insertions, 10 deletions
diff --git a/docs/_config.yml b/docs/_config.yml
index 11eecb6..e97aba3 100644
--- a/docs/_config.yml
+++ b/docs/_config.yml
@@ -16,6 +16,8 @@ navigation:
url: /docs/results/
- text: Jobs
url: /docs/jobs/
+ - text: Exceptions
+ url: /docs/exceptions/
- text: Scheduling Jobs
url: /docs/scheduling/
- text: Monitoring
@@ -23,9 +25,7 @@ navigation:
- text: Job Registries
url: /docs/job_registries/
- text: Connections
- url: /docs/connections/
- - text: Exceptions
- url: /docs/exceptions/
+ url: /docs/connections/
- text: Testing
url: /docs/testing/
- text: Patterns
diff --git a/docs/docs/exceptions.md b/docs/docs/exceptions.md
index d9b1827..2510ebf 100644
--- a/docs/docs/exceptions.md
+++ b/docs/docs/exceptions.md
@@ -1,17 +1,64 @@
---
-title: "RQ: Exceptions"
+title: "RQ: Exceptions & Retries"
layout: docs
---
-Jobs can fail due to exceptions occurring. When your RQ workers run in the
+Jobs can fail due to exceptions occurring. When your RQ workers run in the
background, how do you get notified of these exceptions?
-## Default: the `FailedJobRegistry`
+## Default: FailedJobRegistry
The default safety net for RQ is the `FailedJobRegistry`. Every job that doesn't
execute successfully is stored here, along with its exception information (type,
-value, traceback). While this makes sure no failing jobs "get lost", this is
-of no use to get notified pro-actively about job failure.
+value, traceback).
+
+```python
+from redis import Redis
+from rq import Queue
+from rq.registry import FailedJobRegistry
+
+redis = Redis()
+queue = Queue(connection=redis)
+registry = FailedJobRegistry(queue=queue)
+
+# Show all failed job IDs and the exceptions they caused during runtime
+for job_id in registry.get_job_ids():
+ job = Job.fetch(job_id, connection=redis)
+ print(job_id, job.exc_info)
+```
+
+## Retrying Failed Jobs
+
+_New in version 1.5.0_
+
+RQ lets you easily retry failed jobs. To configure retries, use RQ's
+`Retry` object that accepts `max` and `interval` arguments. For example:
+
+```python
+from redis import Redis
+from rq import Retry, Queue
+
+from somewhere import my_func
+
+queue = Queue(connection=redis)
+# Retry up to 3 times, failed job will be requeued immediately
+queue.enqueue(my_func, retry=Retry(max=3))
+
+# Retry up to 3 times, with 60 seconds interval in between executions
+queue.enqueue(my_func, retry=Retry(max=3, interval=60))
+
+# Retry up to 3 times, with longer interval in between retries
+queue.enqueue(my_func, retry=Retry(max=3, interval=[10, 30, 60]))
+```
+
+<div class="warning">
+ <img style="float: right; margin-right: -60px; margin-top: -38px" src="/img/warning.png" />
+ <strong>Note:</strong>
+ <p>
+ If you use `interval` argument with `Retry`, don't forget to run your workers using
+ the `--with-scheduler` argument.
+ </p>
+</div>
## Custom Exception Handlers
diff --git a/docs/docs/scheduling.md b/docs/docs/scheduling.md
index 7ecff03..7d27ba9 100644
--- a/docs/docs/scheduling.md
+++ b/docs/docs/scheduling.md
@@ -20,7 +20,7 @@ RQ to have job scheduling capabilities without:
2. Worrying about a separate `Scheduler` class.
-# Scheduling Jobs for Execution
+## Scheduling Jobs for Execution
There are two main APIs to schedule jobs for execution, `enqueue_at()` and `enqueue_in()`.
@@ -76,7 +76,7 @@ registry = ScheduledJobRegistry(queue=queue)
print(job in registry) # Outputs True as job is placed in ScheduledJobRegistry
```
-# Running the Scheduler
+## Running the Scheduler
If you use RQ's scheduling features, you need to run RQ workers with the
scheduler component enabled.