3

I have 1 failed job on failed queue.

$ rq info
failed       |█ 1

1 queues, 1 jobs total

As answered by @Byron Ruth, I can get that number this way:

from rq import Queue
from redis import Redis

q = Queue('failed', connection=Redis())
print len (q.jobs)

On rq-dashboard, I see the traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 588, in perform_job
    rv = job.perform()
    ...

How can I get this traceback using Python code? If that is not possible, any programmatic solution is acceptable (e.g. via Bash).

  • you may use rq-dashboard to monitor your queues for traceback logs – Anand Joshi Jun 10 '20 at 00:33
  • @AnandJoshi, in the original question, I explicitly stated that I see the traceback on rq-dashboard, so that is already known. I was asking how to do it from code (which can be found out by following accepted answer). I'm sorry, but I fail to see which new information your comment is introducing to this topic. – Muhamed Huseinbašić Jun 16 '20 at 06:31

1 Answers1

6

Not sure whether you have found out the solution. You can get the traceback from exc_info call. For example:

>>> print(get_failed_queue().jobs[0].exc_info)
Traceback (most recent call last):
  File "/Users/ubuntu/.venv/lib/python3.5/site-packages/rq/worker.py", line 700, in perform_job
    rv = job.perform()
  File "/Users/ubuntu/.venv/lib/python3.5/site-packages/rq/job.py", line 500, in perform
    self._result = self.func(*self.args, **self.kwargs)
  File "/Users/ubuntu/foo.py", line 17, in foobar
    1/0
ZeroDivisionError: division by zero
hzm
  • 420
  • 4
  • 9