From 8a0d9f91ff7927051e8df6084abd501e3d31613d Mon Sep 17 00:00:00 2001 From: David Murray Date: Thu, 23 Jul 2020 08:50:32 -0400 Subject: [PATCH] Fix incorrect worker timeout calculation in SimpleWorker.execute_job (#1304) In our systems, this bug seemed the be the cause of the disappearing workers: worker keys would get a very small TTL in Redis and would eventually expire, thus mysteriously "disappearing" from dashboards. --- rq/worker.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rq/worker.py b/rq/worker.py index 7f443ce..dd9c0fc 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -1034,7 +1034,11 @@ class SimpleWorker(Worker): def execute_job(self, job, queue): """Execute job in same thread/process, do not fork()""" - timeout = (job.timeout or DEFAULT_WORKER_TTL) + 60 + # "-1" means that jobs never timeout. In this case, we should _not_ do -1 + 60 = 59. We should just stick to DEFAULT_WORKER_TTL. + if job.timeout == -1: + timeout = DEFAULT_WORKER_TTL + else: + timeout = (job.timeout or DEFAULT_WORKER_TTL) + 60 return self.perform_job(job, queue, heartbeat_ttl=timeout)