如何从代码中读取失败队列(rq)的回溯?
How to read the traceback on failed queue (rq) from code?
我在 失败 队列上有 1 个失败的作业。
$ rq info
failed |█ 1
1 queues, 1 jobs total
作为@Byron Ruth 的answered,我可以通过这种方式获得该数字:
from rq import Queue
from redis import Redis
q = Queue('failed', connection=Redis())
print len (q.jobs)
在 rq-dashboard 上,我看到了回溯:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 588, in perform_job
rv = job.perform()
...
如何使用 Python 代码获得此回溯?如果那不可能,任何编程解决方案都是可以接受的(例如通过 Bash)。
不确定您是否找到了解决方案。您可以从 exc_info
调用中获取回溯。例如:
>>> 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
我在 失败 队列上有 1 个失败的作业。
$ rq info
failed |█ 1
1 queues, 1 jobs total
作为@Byron Ruth 的answered,我可以通过这种方式获得该数字:
from rq import Queue
from redis import Redis
q = Queue('failed', connection=Redis())
print len (q.jobs)
在 rq-dashboard 上,我看到了回溯:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 588, in perform_job
rv = job.perform()
...
如何使用 Python 代码获得此回溯?如果那不可能,任何编程解决方案都是可以接受的(例如通过 Bash)。
不确定您是否找到了解决方案。您可以从 exc_info
调用中获取回溯。例如:
>>> 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