diff options
author | Ted Summer <ted.summer2@gmail.com> | 2019-05-17 23:39:45 -0500 |
---|---|---|
committer | Selwin Ong <selwin.ong@gmail.com> | 2019-05-18 11:39:45 +0700 |
commit | 79a6fd79997613d446856982f32d06f53093cd8e (patch) | |
tree | b9732c8e51da36c44450fbccdc1dca6195eda04c | |
parent | eed51df14a71bb910e8ce093aa666532a007cacb (diff) | |
download | rq-79a6fd79997613d446856982f32d06f53093cd8e.tar.gz |
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
-rw-r--r-- | rq/worker.py | 5 | ||||
-rw-r--r-- | tests/test_worker.py | 17 |
2 files changed, 21 insertions, 1 deletions
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.""" |