From f226d38603a148ef5209145627481a5db4344b99 Mon Sep 17 00:00:00 2001 From: Theo Date: Tue, 24 Oct 2017 09:32:10 +0100 Subject: [PATCH] Fixed #812 - Send heartbeat during suspension check --- rq/suspension.py | 10 ++++++++-- rq/worker.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/rq/suspension.py b/rq/suspension.py index 93152b9..3e96014 100644 --- a/rq/suspension.py +++ b/rq/suspension.py @@ -1,8 +1,14 @@ WORKERS_SUSPENDED = 'rq:suspended' -def is_suspended(connection): - return connection.exists(WORKERS_SUSPENDED) +def is_suspended(connection, worker=None): + with connection.pipeline() as pipeline: + if worker is not None: + worker.heartbeat(pipeline=pipeline) + pipeline.exists(WORKERS_SUSPENDED) + # pipeline returns a list of responses + # https://github.com/andymccurdy/redis-py#pipelines + return pipeline.execute()[-1] def suspend(connection, ttl=None): diff --git a/rq/worker.py b/rq/worker.py index dd9d0bc..8dd855a 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -416,7 +416,7 @@ class Worker(object): before_state = None notified = False - while not self._stop_requested and is_suspended(self.connection): + while not self._stop_requested and is_suspended(self.connection, self): if burst: self.log.info('Suspended in burst mode, exiting')