|
|
@ -21,23 +21,12 @@ handlers. This makes it possible to replace the default behaviour (sending
|
|
|
|
the job to the `failed` queue) altogether, or to take additional steps when an
|
|
|
|
the job to the `failed` queue) altogether, or to take additional steps when an
|
|
|
|
exception occurs.
|
|
|
|
exception occurs.
|
|
|
|
|
|
|
|
|
|
|
|
To do this, register your custom exception handler to an RQ worker as follows:
|
|
|
|
This is how you register custom exception handler(s) to an RQ worker:
|
|
|
|
|
|
|
|
|
|
|
|
{% highlight python %}
|
|
|
|
{% highlight python %}
|
|
|
|
with Connection():
|
|
|
|
from rq.handlers import move_to_failed_queue # RQ's default exception handler
|
|
|
|
q = Queue()
|
|
|
|
|
|
|
|
w = Worker([q])
|
|
|
|
|
|
|
|
w.push_exc_handler(my_handler)
|
|
|
|
|
|
|
|
w.work()
|
|
|
|
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
While the exception handlers are a FILO stack, most times you only want to
|
|
|
|
|
|
|
|
register a single handler. Therefore, for convenience, you can pass it to the
|
|
|
|
|
|
|
|
constructor directly, too:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{% highlight python %}
|
|
|
|
w = Worker([q], exception_handlers=[my_handler, move_to_failed_queue])
|
|
|
|
with Connection():
|
|
|
|
|
|
|
|
w = Worker([q], exception_handlers=[my_handler, self.move_to_failed_queue])
|
|
|
|
|
|
|
|
...
|
|
|
|
...
|
|
|
|
{% endhighlight %}
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
|
|
|
|