您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

30 行
1.0 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import (absolute_import, division, print_function,
  3. unicode_literals)
  4. import logging
  5. from rq import get_current_connection
  6. from rq import Worker
  7. logger = logging.getLogger(__name__)
  8. def cleanup_ghosts(conn=None):
  9. """
  10. RQ versions < 0.3.6 suffered from a race condition where workers, when
  11. abruptly terminated, did not have a chance to clean up their worker
  12. registration, leading to reports of ghosted workers in `rqinfo`. Since
  13. 0.3.6, new worker registrations automatically expire, and the worker will
  14. make sure to refresh the registrations as long as it's alive.
  15. This function will clean up any of such legacy ghosted workers.
  16. """
  17. conn = conn if conn else get_current_connection()
  18. for worker in Worker.all(connection=conn):
  19. if conn.ttl(worker.key) == -1:
  20. ttl = worker.default_worker_ttl
  21. conn.expire(worker.key, ttl)
  22. logger.info('Marked ghosted worker {0} to expire in {1} seconds.'.format(worker.name, ttl))