8

我正在尝试更改 rq 作业的超时,但似乎没有任何效果。我有一些效果:

my_queue = Queue('my_task', connection=Redis())

job_args = (1, 2, 4)

my_queue.enqueue_call(
                    my_func,
                    args=job_args,
                    timeout=2700
            )

但我仍然得到

JobTimeoutException: Job exceeded maximum timeout value (180 seconds)

我非常绝望,甚至尝试进入 rq 模块 queue.py 并将超时的默认参数更改为 2700 和 DEFAULT_TIMEOUT(在 Queue 类中定义的变量,其中包含 enqueue_call 方法)。我是否遗漏了某些东西,或者任何人都知道这个问题?谢谢!

4

3 回答 3

11

我们可以通过在队列初始化时设置超时来解决这个问题。

from rq import Worker, Queue, Connection
q = Queue(default_timeout=3600)

希望这能解决您的疑问。

于 2017-03-10T11:57:11.043 回答
4

利用

my_queue = Queue('my_task', connection=Redis())
job_args = [1, 2, 4]

my_queue.enqueue_call(
                f=my_func,
                job_timeout=2700,
                args=job_args
        )

timeout 不是正确的参数名称。检查 queue.py 中所有其他参数名称的“parse_args”函数

于 2020-04-13T20:22:27.247 回答
3

enqueue_call 中的超时参数没有问题。刚刚用这个例子进行了测试。

函数.py

from time import sleep
def test(a, b, c):
    sleep(a)
    print str(b+c)

驱动程序.py

from redis import Redis
from rq import Queue
from function import test

q = Queue('abc', connection=Redis())

q.enqueue_call(test, args=(300, 2, 3), timeout=200)
q.enqueue_call(test, args=(100, 2, 3), timeout=200)

结果:

13:08:11 abc: test.test(100, 2, 3) (4b4e96e5-af30-4175-ab94-ceaf9187e581)
5
13:08:13 abc: test.test(300, 2, 3) (04605c34-d039-42ad-954e-7f445f0f8bc9)
13:11:17 JobTimeoutException: Job exceeded maximum timeout value (200 seconds)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 568, in perform_job
    rv = job.perform()
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 495, in perform
    self._result = self.func(*self.args, **self.kwargs)
  File "./test.py", line 4, in test
    sleep(a)
  File "/usr/local/lib/python2.7/dist-packages/rq/timeouts.py", line 51, in handle_death_penalty
    'value ({0} seconds)'.format(self._timeout))
JobTimeoutException: Job exceeded maximum timeout value (200 seconds)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 568, in perform_job
    rv = job.perform()
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 495, in perform
    self._result = self.func(*self.args, **self.kwargs)
  File "./test.py", line 4, in test
    sleep(a)
  File "/usr/local/lib/python2.7/dist-packages/rq/timeouts.py", line 51, in handle_death_penalty
    'value ({0} seconds)'.format(self._timeout))
JobTimeoutException: Job exceeded maximum timeout value (200 seconds)

如果您使用 supervisor 之类的工具来管理 rq worker,请尝试重新启动服务。

于 2016-04-29T08:06:39.710 回答