diff --git a/rq/timeouts.py b/rq/timeouts.py index a1401c5c..44f01f9e 100644 --- a/rq/timeouts.py +++ b/rq/timeouts.py @@ -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 diff --git a/tests/test_timeouts.py b/tests/test_timeouts.py index 2872ee02..1f392a38 100644 --- a/tests/test_timeouts.py +++ b/tests/test_timeouts.py @@ -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)