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
main
Ted Summer 6 years ago committed by Selwin Ong
parent eed51df14a
commit 79a6fd7999

@ -699,7 +699,10 @@ class Worker(object):
"""Performs misc bookkeeping like updating states prior to """Performs misc bookkeeping like updating states prior to
job execution. 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: if heartbeat_ttl is None:
heartbeat_ttl = self.job_monitoring_interval + 5 heartbeat_ttl = self.job_monitoring_interval + 5

@ -616,6 +616,23 @@ class TestWorker(RQTestCase):
# Updates worker statuses # Updates worker statuses
self.assertEqual(worker.get_state(), 'busy') self.assertEqual(worker.get_state(), 'busy')
self.assertEqual(worker.get_current_job_id(), job.id) 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): def test_work_unicode_friendly(self):
"""Worker processes work with unicode description, then quits.""" """Worker processes work with unicode description, then quits."""

Loading…
Cancel
Save