Skip to content

Instantly share code, notes, and snippets.

@ecarreras
Created February 5, 2018 12:51
Show Gist options
  • Save ecarreras/84f386014c4c24dec10d953f28fdae23 to your computer and use it in GitHub Desktop.
Save ecarreras/84f386014c4c24dec10d953f28fdae23 to your computer and use it in GitHub Desktop.
Clean some inconsistency in rq
from redis import StrictRedis
from rq.job import Job
from rq import push_connection, get_failed_queue
from collections import Counter
from tqdm import tqdm
stats = {'queue': Counter(), 'status': Counter()}
conn = StrictRedis.from_url()
push_connection(conn)
keys = conn.keys('rq:job:*')
failed_jobs = get_failed_queue().get_job_ids()
for key in tqdm(keys):
job_id = key.split(':')[-1]
try:
job = Job.fetch(job_id)
job_status = job.get_status()
stats['queue'][job.origin] += 1
stats['status'][job_status] += 1
if job_status == 'deferred':
try:
dep = job.dependency
except:
job.delete(delete_dependents=True)
elif job_status == 'failed' and job.id not in failed_jobs:
job.delete(delete_dependents=True)
except:
if len(job_id.split('-')) == 5:
conn.expire(key, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment