fix_cleanup_ghosts_by_using_configured_worker_class (#1988)

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>
This commit is contained in:
Simó Albert i Beltran 2023-10-07 02:09:32 +02:00 committed by GitHub
parent 626378cb32
commit 235a87d01e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -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))

View File

@ -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)