From 79a6fd79997613d446856982f32d06f53093cd8e Mon Sep 17 00:00:00 2001 From: Ted Summer Date: Fri, 17 May 2019 23:39:45 -0500 Subject: [PATCH] Fix timeout adding job to StartedJobRegistry (#1086) * Fix timeout adding job to StartedJobRegistry * Fix prepare_job_execution handling neg timeout * Add test for inf job timeout in StartedJobRegistry * refactor(worker): simplify checking neg timeout --- rq/worker.py | 5 ++++- tests/test_worker.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/rq/worker.py b/rq/worker.py index 2dbb27f..0ae0edd 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -699,7 +699,10 @@ class Worker(object): """Performs misc bookkeeping like updating states prior to job execution. """ - timeout = (job.timeout or 180) + 60 + if job.timeout == -1: + timeout = -1 + else: + timeout = job.timeout or 180 if heartbeat_ttl is None: heartbeat_ttl = self.job_monitoring_interval + 5 diff --git a/tests/test_worker.py b/tests/test_worker.py index 007c653..91fa93b 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -616,6 +616,23 @@ class TestWorker(RQTestCase): # Updates worker statuses self.assertEqual(worker.get_state(), 'busy') self.assertEqual(worker.get_current_job_id(), job.id) + + def test_prepare_job_execution_inf_timeout(self): + """Prepare job execution handles infinite job timeout""" + queue = Queue(connection=self.testconn) + job = queue.enqueue(long_running_job, + args=(1,), + job_timeout=-1) + worker = Worker([queue]) + worker.prepare_job_execution(job) + + # Updates working queue + registry = StartedJobRegistry(connection=self.testconn) + self.assertEqual(registry.get_job_ids(), [job.id]) + + # Score in queue is +inf + self.assertEqual(self.testconn.zscore(registry.key, job.id), float('Inf')) + def test_work_unicode_friendly(self): """Worker processes work with unicode description, then quits."""