summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Stowers <john.stowers@gmail.com>2018-10-27 06:42:31 +0200
committerSelwin Ong <selwin.ong@gmail.com>2018-10-27 11:42:31 +0700
commiteaf598d73ce234791ee22ef82f7f095aece9f2a6 (patch)
tree0d61427d05307294a23fc3a37b7f8bdbd628ec7b
parentad66d872f0a51579ccdf245ef73358e7678a43f2 (diff)
downloadrq-eaf598d73ce234791ee22ef82f7f095aece9f2a6.tar.gz
Pass job_id to death penalty class (#936)
This allows custom workers to use associated custom Timeout classes and apply custom timeouts or less messy death methods
-rw-r--r--docs/docs/workers.md10
-rw-r--r--rq/timeouts.py2
-rw-r--r--rq/worker.py2
3 files changed, 12 insertions, 2 deletions
diff --git a/docs/docs/workers.md b/docs/docs/workers.md
index 414d89c..e3d205e 100644
--- a/docs/docs/workers.md
+++ b/docs/docs/workers.md
@@ -290,6 +290,16 @@ queue.enqueue(some_func)
{% endhighlight %}
+## Custom DeathPenalty classes
+
+When a Job times-out, the worker will try to kill it using the supplied
+`death_penalty_class` (default: `UnixSignalDeathPenalty`). This can be overridden
+if you wish to attempt to kill jobs in an application specific or 'cleaner' manner.
+
+DeathPenalty classes are constructed with the following arguments
+`BaseDeathPenalty(timeout, JobTimeoutException, job_id=job.id)`
+
+
## Custom exception handlers
_New in version 0.5.5._
diff --git a/rq/timeouts.py b/rq/timeouts.py
index b211097..3f9ac5b 100644
--- a/rq/timeouts.py
+++ b/rq/timeouts.py
@@ -27,7 +27,7 @@ class HorseMonitorTimeoutException(BaseTimeoutException):
class BaseDeathPenalty(object):
"""Base class to setup job timeouts."""
- def __init__(self, timeout, exception=JobTimeoutException):
+ def __init__(self, timeout, exception=JobTimeoutException, **kwargs):
self._timeout = timeout
self._exception = exception
diff --git a/rq/worker.py b/rq/worker.py
index a05a6ba..cdfa33f 100644
--- a/rq/worker.py
+++ b/rq/worker.py
@@ -795,7 +795,7 @@ class Worker(object):
try:
job.started_at = utcnow()
timeout = job.timeout or self.queue_class.DEFAULT_TIMEOUT
- with self.death_penalty_class(timeout, JobTimeoutException):
+ with self.death_penalty_class(timeout, JobTimeoutException, job_id=job.id):
rv = job.perform()
job.ended_at = utcnow()