0

我正在尝试按照 rq文档interval使用 rq Retry 功能,但是在使用参数时它不起作用

  • 蟒蛇版本:3.8.0
  • rq 版本:1.10.0

somewhere.py

def my_func():
     print('Start...')
     asdsa # Here a NameError is raised

my_func使用重试功能排队的脚本

from redis import Redis
from rq import Retry, Queue

from somewhere import my_func


r = Redis("localhost",
    6379,
    socket_connect_timeout=1,
    decode_responses=True,
)

q = Queue(connection=r)
q.enqueue(my_func, retry=Retry(max=3, interval=10))

我期待看到工人my_func以 10 秒的间隔运行 3 次,但实际上它只运行一次。工人输出:

17:35:19 Worker rq:worker:1801215fdd1040b2aee962cccceff587: started, version 1.10.1
17:35:19 Subscribing to channel rq:pubsub:1801215fdd1040b2aee962cccceff587
17:35:19 *** Listening on default...
17:35:22 default: somewhere.my_func() (dc051976-598a-4863-8d15-6813c61d1377)
1
17:35:22 Traceback (most recent call last):
  File "/home/user/Documents/Projects/Aquacrop/aquacrop/aquacrop-api/env/lib/python3.8/site-packages/rq/worker.py", line 1061, in perform_job
    rv = job.perform()
  File "/home/user/Documents/Projects/Aquacrop/aquacrop/aquacrop-api/env/lib/python3.8/site-packages/rq/job.py", line 821, in perform
    self._result = self._execute()
  File "/home/user/Documents/Projects/Aquacrop/aquacrop/aquacrop-api/env/lib/python3.8/site-packages/rq/job.py", line 844, in _execute
    result = self.func(*self.args, **self.kwargs)
  File "./somewhere.py", line 3, in my_func
    somewhere
NameError: name 'somewhere' is not defined
Traceback (most recent call last):
  File "/home/user/Documents/Projects/Aquacrop/aquacrop/aquacrop-api/env/lib/python3.8/site-packages/rq/worker.py", line 1061, in perform_job
    rv = job.perform()
  File "/home/user/Documents/Projects/Aquacrop/aquacrop/aquacrop-api/env/lib/python3.8/site-packages/rq/job.py", line 821, in perform
    self._result = self._execute()
  File "/home/user/Documents/Projects/Aquacrop/aquacrop/aquacrop-api/env/lib/python3.8/site-packages/rq/job.py", line 844, in _execute
    result = self.func(*self.args, **self.kwargs)
  File "./somewhere.py", line 3, in my_func
    somewhere
NameError: name 'somewhere' is not defined

如果我不使用该interval参数,则工作人员会按预期重试该函数 3 次。

我究竟做错了什么?

4

1 回答 1

0

正如这里这里--with-scheduler所说的那样,必须使用标志运行工人,例如:

rq worker --url redis://localhost:6379 --with-scheduler
于 2022-02-28T08:28:53.043 回答