summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo <theo.despoudis@teckro.com>2017-10-24 09:32:10 +0100
committerTheo <theo.despoudis@teckro.com>2017-10-24 09:32:10 +0100
commitf226d38603a148ef5209145627481a5db4344b99 (patch)
treedde92ebb343f52437672f8ec4dba86e2bade3661
parent92c88d3f4da0f17b5c2d927a18282819e74e0fa6 (diff)
downloadrq-f226d38603a148ef5209145627481a5db4344b99.tar.gz
Fixed #812 - Send heartbeat during suspension check
-rw-r--r--rq/suspension.py10
-rw-r--r--rq/worker.py2
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')