Skip to content

Instantly share code, notes, and snippets.

@hirobert
Created October 12, 2023 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirobert/8ae2211c2d7f0d7f1046d717704e5f88 to your computer and use it in GitHub Desktop.
Save hirobert/8ae2211c2d7f0d7f1046d717704e5f88 to your computer and use it in GitHub Desktop.
Fix Stuck Jobs in RQ Failed Queue
# If RQ thinks there are failed jobs
# but they do not exist in Redis
# and RQ-Dashboard cannot remove/requeue them
from redis import Redis
from rq import Queue
from rq.registry import FailedJobRegistry
from rq.exceptions import NoSuchJobError
redis_rq = Redis(host=REDIS_SERVER, port=6379, db=1)
queue = Queue(name="low", connection=redis_rq)
registry = FailedJobRegistry(queue=queue)
print(registry.count)
for job_id in registry.get_job_ids():
try:
registry.requeue(job_id)
except NoSuchJobError:
registry.remove(job_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment