From 235a87d01ee2f03f6c125fa77b29b2dbdfaa8a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sim=C3=B3=20Albert=20i=20Beltran?= Date: Sat, 7 Oct 2023 02:09:32 +0200 Subject: [PATCH] fix_cleanup_ghosts_by_using_configured_worker_class (#1988) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simó Albert i Beltran --- rq/cli/cli.py | 2 +- rq/contrib/legacy.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rq/cli/cli.py b/rq/cli/cli.py index 7f8b6d09..8b0602ae 100755 --- a/rq/cli/cli.py +++ b/rq/cli/cli.py @@ -256,7 +256,7 @@ def worker( setup_loghandlers_from_args(verbose, quiet, date_format, log_format) try: - cleanup_ghosts(cli_config.connection) + cleanup_ghosts(cli_config.connection, worker_class=cli_config.worker_class) exception_handlers = [] for h in exception_handler: exception_handlers.append(import_attribute(h)) diff --git a/rq/contrib/legacy.py b/rq/contrib/legacy.py index be44b65a..9362d697 100644 --- a/rq/contrib/legacy.py +++ b/rq/contrib/legacy.py @@ -5,7 +5,7 @@ from rq import Worker, get_current_connection logger = logging.getLogger(__name__) -def cleanup_ghosts(conn=None): +def cleanup_ghosts(conn=None, worker_class=Worker): """ 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 @@ -16,7 +16,7 @@ def cleanup_ghosts(conn=None): This function will clean up any of such legacy ghosted workers. """ conn = conn if conn else get_current_connection() - for worker in Worker.all(connection=conn): + for worker in worker_class.all(connection=conn): if conn.ttl(worker.key) == -1: ttl = worker.worker_ttl conn.expire(worker.key, ttl)