def check_failed_rq_jobs(queue_name='monitoring_tasks', delete_job=False): """This function will print out jobs that failed to execute on RQ 's task queue""" queue = Queue(connection=app.redis, name=queue_name) registry = FailedJobRegistry(queue=queue) # This is how to remove a job from a registry for job_id in registry.get_job_ids(): # Get job whose ID is given job = Job.fetch(job_id, connection=app.redis) # Print out the job's exception stacktrace system_logging(f'\n{job.__dict__["exc_info"]}\n------------------------------------------\n', True, 'redis.log') # Remove from registry and delete job registry.remove(job_id, delete_job=delete_job)
def handle(self, *args, **options): with Connection(REDIS_CLIENT): workers = Worker.all(REDIS_CLIENT) for worker in workers: send_kill_horse_command(REDIS_CLIENT, worker.name) send_shutdown_command(REDIS_CLIENT, worker.name) worker.register_death() job_ids = AsyncCronMail.objects.values_list('job_id').filter(started_at__isnull=False,status=False).first() if AsyncCronMail.objects.filter(started_at__isnull=False,status=False).count() > 0: try: job = Job.fetch(job_ids[0], connection=REDIS_CLIENT) DEFAULT_QUEUE.empty() DEFAULT_QUEUE.enqueue_job(job) except: print('Job does not exist') topper_registry = FailedJobRegistry(queue=TOPPER_QUEUE) for job_id in topper_registry.get_job_ids(): topper_registry.remove(job_id, delete_job=True) w = Worker([DEFAULT_QUEUE,TOPPER_QUEUE], connection=REDIS_CLIENT, name='default_worker') w.work()
import pdfkit from rq import Worker, Queue, Connection from redis import Redis from rq.job import Job from rq.registry import FailedJobRegistry, ScheduledJobRegistry from apscheduler.schedulers.background import BackgroundScheduler app = Flask(__name__) cors = CORS(app, resources={r"/*": {"origins": "*"}}) redis_conn = Redis(host='redis', port=6379) q = Queue(connection=redis_conn) failed_registry = FailedJobRegistry(queue=q) for job_id in failed_registry.get_job_ids(): app.logger.error("fal del-> " + str(job_id)) failed_registry.remove(job_id, delete_job=True) sch_registry = ScheduledJobRegistry(queue=q) for job_id in sch_registry.get_job_ids(): app.logger.error("sch del-> " + str(job_id)) sch_registry.remove(job_id, delete_job=True) def job_function(): con = conDB.newCon() data = conDB.getPDFs(con).fetchall() # ter em conta time out to job result # ver se status é 0 o u 1 antes de chamar result for i in data: if i[6] == 0: # status for 0 faz call para obter resultado do job job = Job.fetch(i[5], connection=redis_conn)
def failed_clear(): registry_failed = FailedJobRegistry(queue=q) for job_id in registry_failed.get_job_ids(): registry_failed.remove(job_id, delete_job=True) return redirect("/")