rq timeout param in enqueue call not working, giving JobTimeoutException
Asked Answered
W

3

9

I am trying to change the timeout on an rq job but nothing seems to work. I've got something to the effect of:

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

job_args = (1, 2, 4)

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

but I'm still getting

JobTimeoutException: Job exceeded maximum timeout value (180 seconds)

I've got so desperate I even tried going into the rq module queue.py and changing the default argument for timeout to 2700 and DEFAULT_TIMEOUT (variable defined in the Queue class, which contains the enqueue_call method). Am I missing something or is there an issue with this anyone knows about? Thanks!

Wards answered 27/4, 2016 at 18:40 Comment(1)
Then why didnt you made an issue?Addition
T
18

We can tackle this by setting the timeout at Queue initialization.

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

Hope this will solve your query.

Table answered 10/3, 2017 at 11:57 Comment(1)
This worked for me . rq==1.6.1, redis==3.5.3Sherwin
R
4

Use

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 is not the correct parameter name. Check "parse_args" function for all other parameter names in queue.py

Revamp answered 13/4, 2020 at 20:22 Comment(1)
This is wrong. enqueue_call() takes the parameter timeout, and enqueue() takes the parameter job_timeout.Merrymerryandrew
I
3

There are no issues with timeout argument in enqueue_call. Just tested it out with this example.

function.py

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

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

Result:

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)

If you are using tools like supervisor to manage rq workers, try restarting the service.

Indihar answered 29/4, 2016 at 8:6 Comment(2)
I did restart the service, but I still get the same issue.Wards
Difficult to decode without looking at the code. You can try using @job decorator. docsIndihar

© 2022 - 2024 — McMap. All rights reserved.