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
main
John Stowers 6 years ago committed by Selwin Ong
parent ad66d872f0
commit eaf598d73c

@ -290,6 +290,16 @@ queue.enqueue(some_func)
{% endhighlight %} {% 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 ## Custom exception handlers
_New in version 0.5.5._ _New in version 0.5.5._

@ -27,7 +27,7 @@ class HorseMonitorTimeoutException(BaseTimeoutException):
class BaseDeathPenalty(object): class BaseDeathPenalty(object):
"""Base class to setup job timeouts.""" """Base class to setup job timeouts."""
def __init__(self, timeout, exception=JobTimeoutException): def __init__(self, timeout, exception=JobTimeoutException, **kwargs):
self._timeout = timeout self._timeout = timeout
self._exception = exception self._exception = exception

@ -795,7 +795,7 @@ class Worker(object):
try: try:
job.started_at = utcnow() job.started_at = utcnow()
timeout = job.timeout or self.queue_class.DEFAULT_TIMEOUT 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() rv = job.perform()
job.ended_at = utcnow() job.ended_at = utcnow()

Loading…
Cancel
Save