Skip to content

Commit

Permalink
Fixed rq#812 - Send heartbeat during suspension check
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo committed Oct 24, 2017
1 parent 92c88d3 commit f226d38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions rq/suspension.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion rq/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def check_for_suspension(self, burst):
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')
Expand Down

0 comments on commit f226d38

Please sign in to comment.