Fix - TypeError - accessing None when dequeued result is None (when timeout=None, e.g. in burst mode) (#1793)

* fix accessing None when dequeued result is None (burst=True, or timeout=None)

* add a test

* pr fix

* fix tests
main
Rony Lutsky 2 years ago committed by GitHub
parent 83fa0adf15
commit 54db2fa8d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -757,8 +757,8 @@ class Worker:
serializer=self.serializer, serializer=self.serializer,
) )
if result is not None: if result is not None:
self.log.debug(f"Dequeued job {blue(result[0].id)} from {green(result[1].name)}")
job, queue = result job, queue = result
self.log.debug(f"Dequeued job {blue(job.id)} from {green(queue.name)}")
job.redis_server_version = self.get_redis_server_version() job.redis_server_version = self.get_redis_server_version()
if self.log_job_description: if self.log_job_description:
self.log.info('%s: %s (%s)', green(queue.name), blue(job.description), job.id) self.log.info('%s: %s (%s)', green(queue.name), blue(job.description), job.id)

@ -634,6 +634,14 @@ class TestWorker(RQTestCase):
res.refresh() res.refresh()
self.assertIn('JobTimeoutException', as_text(res.exc_info)) self.assertIn('JobTimeoutException', as_text(res.exc_info))
def test_dequeue_job_and_maintain_ttl_non_blocking(self):
"""Not passing a timeout should return immediately with None as a result"""
q = Queue()
w = Worker([q])
# Put it on the queue with a timeout value
self.assertIsNone(w.dequeue_job_and_maintain_ttl(None))
def test_worker_sets_result_ttl(self): def test_worker_sets_result_ttl(self):
"""Ensure that Worker properly sets result_ttl for individual jobs.""" """Ensure that Worker properly sets result_ttl for individual jobs."""
q = Queue() q = Queue()

Loading…
Cancel
Save