You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

25 lines
750 B

  1. WORKERS_SUSPENDED = 'rq:suspended'
  2. def is_suspended(connection, worker=None):
  3. with connection.pipeline() as pipeline:
  4. if worker is not None:
  5. worker.heartbeat(pipeline=pipeline)
  6. pipeline.exists(WORKERS_SUSPENDED)
  7. # pipeline returns a list of responses
  8. # https://github.com/andymccurdy/redis-py#pipelines
  9. return pipeline.execute()[-1]
  10. def suspend(connection, ttl=None):
  11. """ttl = time to live in seconds. Default is no expiration
  12. Note: If you pass in 0 it will invalidate right away
  13. """
  14. connection.set(WORKERS_SUSPENDED, 1)
  15. if ttl is not None:
  16. connection.expire(WORKERS_SUSPENDED, ttl)
  17. def resume(connection):
  18. return connection.delete(WORKERS_SUSPENDED)