diff --git a/rq/contrib/legacy.py b/rq/contrib/legacy.py index 447c002..710c2e3 100644 --- a/rq/contrib/legacy.py +++ b/rq/contrib/legacy.py @@ -11,7 +11,7 @@ from rq import Worker logger = logging.getLogger(__name__) -def cleanup_ghosts(): +def cleanup_ghosts(conn=None): """ RQ versions < 0.3.6 suffered from a race condition where workers, when abruptly terminated, did not have a chance to clean up their worker @@ -21,8 +21,8 @@ def cleanup_ghosts(): This function will clean up any of such legacy ghosted workers. """ - conn = get_current_connection() - for worker in Worker.all(): + conn = conn if conn else get_current_connection() + for worker in Worker.all(connection=conn): if conn._ttl(worker.key) == -1: ttl = worker.default_worker_ttl conn.expire(worker.key, ttl)