Redis 队列重试不适用于间隔参数

发布于 2025-01-09 22:10:49 字数 2428 浏览 1 评论 0原文

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

  • python 版本: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 3 次,中间间隔 10 秒,但实际上它只运行一次。工作程序输出:

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 次。

我做错了什么?

I am trying to use the rq Retry functionality by following the rq documentation but it does not work when using the interval argument

  • python version: 3.8.0
  • rq version: 1.10.0

The somewhere.py

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

A script that enqueues my_func with retry functionality

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))

I was expecting to see the worker running my_func 3 times with 10 sec intervals in the between but it actually runs it only once. The worker output:

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

If I do not use the interval argument, the worker retries the function 3 times as expected.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时模样 2025-01-16 22:10:49

此处此处必须使用 --with-scheduler 标志运行工作程序,例如:

rq worker --url redis://localhost:6379 --with-scheduler

As sated here and here one has to run the worker with the --with-scheduler flag, like:

rq worker --url redis://localhost:6379 --with-scheduler
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文