Fix TimerDeathPenalty not properly handling negative/infinite timeout (#1845)

* Fix TimerDeathPenalty not properly handling negative/infinite timeout

* revert back to using exc_info

---------

Co-authored-by: Marcus <marcus@us2.ai>
This commit is contained in:
Marcus Ong 2023-03-03 07:02:07 +08:00 committed by GitHub
parent ed59b9248a
commit e92682c83a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -110,10 +110,14 @@ class TimerDeathPenalty(BaseDeathPenalty):
def setup_death_penalty(self):
"""Starts the timer."""
if self._timeout <= 0:
return
self._timer = self.new_timer()
self._timer.start()
def cancel_death_penalty(self):
"""Cancels the timer."""
if self._timeout <= 0:
return
self._timer.cancel()
self._timer = None

View File

@ -42,3 +42,10 @@ class TestTimeouts(RQTestCase):
self.assertIn(job, failed_job_registry)
job.refresh()
self.assertIn("rq.timeouts.JobTimeoutException", job.exc_info)
# Test negative timeout doesn't raise JobTimeoutException,
# which implies an unintended immediate timeout.
job = q.enqueue(thread_friendly_sleep_func, args=(1,), job_timeout=-1)
w.work(burst=True)
job.refresh()
self.assertIn(job, finished_job_registry)