"""Updater-owned RQ suspension/drain. No registry cleanup or task cancellation.""" import json import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "alpha.settings") import django django.setup() import django_rq from rq.registry import StartedJobRegistry from rq.suspension import suspend, resume, is_suspended result = {} for name in ("default", "high", "log"): connection = django_rq.get_connection(name) if cfg["action"] == "suspend": suspend(connection) elif cfg["action"] == "resume": resume(connection) # get_job_ids(cleanup=False) must not discard stale/unknown running work. registry = StartedJobRegistry(name, connection=connection) result[name] = { "suspended": is_suspended(connection), "active": len(registry.get_job_ids(cleanup=False)), # Read the pinned RQ 2.x worker hashes directly; Worker.all()/find_by_key # may clean orphan registry entries while reporting status. "busy": sum(connection.hget(key, "state") in (b"busy", "busy") for key in connection.smembers("rq:workers")), } print(json.dumps(result))