pythonredispython-rqrq

Redis queue Retry does not work with the interval argument


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

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?


Solution

  • 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