def requeue_all(self): fq = get_failed_queue() job_ids = fq.job_ids count = len(job_ids) for job_id in job_ids: requeue_job(job_id) redirect(URL())
def form_valid(self, form): form.save() action = form.cleaned_data if action == 'cancel_selected': # django forms don't support "getlist" job_ids = self.request.POST.getlist('_selected_action') for job_id in job_ids: cancel_job(job_id, self.connection) # this has the side effect of flushing the canceled jobs, # otherwise on redirect you may get an empty list.. form.queue.get_jobs(0, len(job_ids)) elif action == 'requeue_selected': job_ids = self.request.POST.getlist('_selected_action') for job_id in job_ids: requeue_job(job_id, self.connection) form.queue.get_jobs(0, len(job_ids)) msgs = { 'compact': __('Queue compacted'), 'empty': __('Queue emptied'), 'requeue': __('Jobs requeued'), 'cancel_selected': __('Selected jobs canceled'), 'requeue_selected': __('Selected jobs requeued'), } messages.success(self.request, msgs[action]) return super(QueueDetails, self).form_valid(form)
def requeue_all(queue_name): fq = Queue(queue_name).failed_job_registry job_ids = fq.get_job_ids() count = len(job_ids) for job_id in job_ids: requeue_job(job_id, connection=current_app.redis_conn) return dict(status='OK', count=count)
def get_rqinfo(options): """获取rq队列信息 """ redis_conn = Redis.from_url(options.connection) push_connection(redis_conn) # RQ队列信息获取操作 if options.status: workers = Worker.all() queues = Queue.all() return workers, queues if options.queue: queue = Queue(options.queue) return queue if options.cancel_job: cancel_job(options.cancel_job) return 'OK' if options.requeue_job: requeue_job(options.requeue_job) return 'OK' if options.requeue_all: return requeue_all() if options.empty_queue: empty_queue(options.empty_queue) return 'OK' if options.compact_queue: compact_queue(options.compact_queue) return 'OK' if options.queues: return list_queues() if options.jobs: return list_jobs(options.jobs) if options.workers: return list_workers() pop_connection()
def actions(request, queue_index): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) if request.method == 'POST' and request.POST.get('action', False): # confirm action if request.POST.get('_selected_action', False): context_data = { 'queue_index': queue_index, 'action': request.POST['action'], 'job_ids': request.POST.getlist('_selected_action'), 'queue': queue, } return render(request, 'django_rq/confirm_action.html', context_data) # do confirmed action elif request.POST.get('job_ids', False): job_ids = request.POST.getlist('job_ids') if request.POST['action'] == 'delete': for job_id in job_ids: job = Job.fetch(job_id, connection=queue.connection) # Remove job id from queue and delete the actual job queue.connection._lrem(queue.key, 0, job.id) job.delete() messages.info(request, 'You have successfully deleted %s jobs!' % len(job_ids)) elif request.POST['action'] == 'requeue': for job_id in job_ids: requeue_job(job_id, connection=queue.connection) messages.info(request, 'You have successfully requeued %d jobs!' % len(job_ids)) return redirect('rq_jobs', queue_index)
def requeue_all(): fq = get_failed_queue() job_ids = fq.job_ids count = len(job_ids) for job_id in job_ids: requeue_job(job_id, connection=current_app.redis_conn) return dict(status='OK', count=count)
def actions(request, queue_index): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) if request.method == "POST" and request.POST.get("action", False): # Confirmation page for selected Action if request.POST.get("_selected_action", False): context_data = { "title": "Are you sure?", "queue_index": queue_index, "action": request.POST["action"], "job_ids": request.POST.getlist("_selected_action"), "queue": queue, } return render(request, "django_rq/confirm_action.html", context_data) # Performing the actual action elif request.POST.get("job_ids", False): job_ids = request.POST.getlist("job_ids") if request.POST["action"] == "delete": for job_id in job_ids: job = Job.fetch(job_id, connection=queue.connection) # Remove job id from queue and delete the actual job queue.connection._lrem(queue.key, 0, job.id) job.delete() messages.info(request, "You have successfully deleted %s jobs!" % len(job_ids)) elif request.POST["action"] == "requeue": # pragma: no cover for job_id in job_ids: requeue_job(job_id, connection=queue.connection) messages.info(request, "You have successfully requeued %d jobs!" % len(job_ids)) return redirect("rq_jobs", queue_index)
def requeue_all(): fq = get_failed_queue() job_ids = fq.job_ids count = len(job_ids) for job_id in job_ids: requeue_job(job_id) return dict(status='OK', count=count)
def maybe_requeue_job(job, exc_type, exc_value, traceback): # If the job raised RequeueJob, requeue it. # (This is done here in an rq exception handler # because it can't be requeued until it is in the failed job registry.) if isinstance(exc_value, RequeueJob): requeue_job(job.id, None) return False
def save(self): action = self.cleaned_data print self.job.id if action == 'requeue': requeue_job(self.job.id, connection=self.job.connection) elif action == 'cancel': cancel_job(self.job.id, connection=self.job.connection)
def reschedule_all_failed(request): queue = get_failed_queue(django_rq.get_connection()) for job in queue.jobs: requeue_job(job.id, connection=queue.connection) return HttpResponse('Success')
def requeue_all(request, queue_index): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) registry = FailedJobRegistry(queue=queue) if request.method == 'POST': job_ids = registry.get_job_ids() count = 0 # Confirmation received for job_id in job_ids: try: requeue_job(job_id, connection=queue.connection) count += 1 except NoSuchJobError: pass messages.info(request, 'You have successfully requeued %d jobs!' % count) return redirect('rq_jobs', queue_index) context_data = { 'queue_index': queue_index, 'queue': queue, 'total_jobs': len(registry), } return render(request, 'django_rq/requeue_all.html', context_data)
def requeue_job(self, job_id): with Connection(self.redis_conn): try: requeue_job(job_id) status = True except: status = False return status
def requeue_job_view(job_id, state=None): if not state: requeue_job(job_id, connection=current_app.redis_conn) elif state == 'finished': job = Job.fetch(job_id) queue = get_queue(job.origin) queue.enqueue_job(job) return dict(status='OK')
def requeue_all(self): with Connection(redis.from_url(self.url)): q = Queue() reg = FailedJobRegistry() tasks = reg.get_job_ids() for task in tasks: print(task) requeue_job(task, q.connection)
def save(self): action = self.cleaned_data if action == 'compact': self.queue.compact() elif action == 'empty': self.queue.empty() elif action == 'requeue': for job_id in self.queue.job_ids: requeue_job(job_id, connection=self.queue.connection)
def job(self, job_id, queue_name, action): if action == 'cancel': cancel_job(job_id) elif action == 'requeue': requeue_job(job_id) else: raise HTTP(404) if current.request.ajax: return jobs_table(queue_name) redirect(URL())
def requeue_job_view(request, queue_index, job_id): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) job = Job.fetch(job_id, connection=queue.connection) if request.POST: requeue_job(job_id, connection=queue.connection) messages.info(request, "You have successfully requeued %s" % job.id) return redirect("rq_job_detail", queue_index, job_id) context_data = {"queue_index": queue_index, "job": job, "queue": queue} return render(request, "django_rq/delete_job.html", context_data)
def reschedule_all_failed(request): from rq import requeue_job from rq import get_failed_queue from django_rq import get_connection queue = get_failed_queue(get_connection()) for job in queue.jobs: requeue_job(job.id, connection=queue.connection) return HttpResponse('Success')
def requeue_job_view(request, queue_index, job_id): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) job = Job.fetch(job_id, connection=queue.connection) if request.POST: requeue_job(job_id, connection=queue.connection) messages.info(request, 'You have successfully requeued %s' % job.id) return redirect('rq_job_detail', queue_index, job_id) context_data = { 'queue_index': queue_index, 'job': job, 'queue': queue, } return render(request, 'django_rq/delete_job.html', context_data)
def requeue(self, task_id): with Connection(redis.from_url(self.url)): try: q = Queue() task = Job.fetch(task_id) requeue_job(task_id, q.connection) return {'status': 'success', 'data': self.__getdata(task)} except NoSuchJobError: pass except InvalidJobOperation: pass return { 'status': 'error', }
def requeue_job_view(request, queue_connection, queue_name, job_id): queue = DjangoRQ(queue_name, connection_name=queue_connection) job = Job.fetch(job_id, connection=queue.connection) if request.POST: requeue_job(job_id, connection=queue.connection) messages.info(request, 'You have successfully requeued %s' % job.id) return redirect('rq_job_detail', queue_connection, queue_name, job_id) context_data = { 'queue_name': queue_name, 'queue_connection': queue_connection, 'job': job, 'queue': queue, } return render(request, 'django_rq/delete_job.html', context_data)
def requeue_job_view(request, queue_index, job_id): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) job = Job.fetch(job_id, connection=queue.connection) if request.method == "POST": try: # pragma: no cover requeue_job(job_id, connection=queue.connection) messages.info(request, "You have successfully requeued %s" % job.id) return redirect("rq_job_detail", queue_index, job_id) except InvalidJobOperationError as e: messages.error(request, e.message) return redirect("rq_jobs", queue_index) context_data = {"title": "Are you sure?", "queue_index": queue_index, "job": job, "queue": queue} return render(request, "django_rq/delete_job.html", context_data)
def check_failed(): """Check the jobs that have failed and requeue them.""" # from rq import Queue, get_failed_queue, requeue_job from rq import Queue, requeue_job from pybossa.core import sentinel from rq.registry import FailedJobRegistry queue_name='maintenance' redis_conn = sentinel.master queue = Queue(queue_name, connection=redis_conn) #fq = get_failed_queue() registry = FailedJobRegistry(queue=queue) job_ids = registry.get_job_ids() #job_ids = fq.job_ids count = len(job_ids) FAILED_JOBS_RETRIES = current_app.config.get('FAILED_JOBS_RETRIES') for job_id in job_ids: KEY = 'pybossa:job:failed:%s' % job_id job = queue.fetch_job(job_id) # job = fq.fetch_job(job_id) if sentinel.slave.exists(KEY): sentinel.master.incr(KEY) else: ttl = current_app.config.get('FAILED_JOBS_MAILS')*24*60*60 sentinel.master.setex(KEY, ttl, 1) if int(sentinel.slave.get(KEY)) < FAILED_JOBS_RETRIES: requeue_job(job_id,connection=redis_conn) else: KEY = 'pybossa:job:failed:mailed:%s' % job_id if (not sentinel.slave.exists(KEY) and current_app.config.get('ADMINS')): subject = "JOB: %s has failed more than 3 times" % job_id body = "Please, review the background jobs of your server." body += "\n This is the trace error\n\n" body += "------------------------------\n\n" body += job.exc_info mail_dict = dict(recipients=current_app.config.get('ADMINS'), subject=subject, body=body) send_mail(mail_dict) ttl = current_app.config.get('FAILED_JOBS_MAILS')*24*60*60 sentinel.master.setex(KEY, ttl, 1) if count > 0: return "JOBS: %s You have failed the system." % job_ids else: return "You have not failed the system"
def requeue_all(request, queue_index): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) jobs = queue.get_jobs() if request.method == 'POST': # Confirmation received for job in jobs: requeue_job(job.id, connection=queue.connection) messages.info(request, 'You have successfully requeued all %d jobs!' % len(jobs)) return redirect('rq_jobs', queue_index) context_data = { 'queue_index': queue_index, 'queue': queue, 'total_jobs':len(jobs), } return render(request, 'django_rq/requeue_all.html', context_data)
def requeue_job_view(request, queue_index, job_id): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) job = Job.fetch(job_id, connection=queue.connection) if request.method == 'POST': try: # pragma: no cover requeue_job(job_id, connection=queue.connection) messages.info(request, 'You have successfully requeued %s' % job.id) return redirect('rq_job_detail', queue_index, job_id) except InvalidJobOperationError as e: messages.error(request, e.message) return redirect('rq_jobs', queue_index) context_data = { 'title': 'Are you sure?', 'queue_index': queue_index, 'job': job, 'queue': queue, } return render(request, 'django_rq/delete_job.html', context_data)
def actions(request, queue_index): queue_index = int(queue_index) queue = get_queue_by_index(queue_index) next_url = request.POST.get('next_url') or reverse('rq_jobs', args=[queue_index]) if request.method == 'POST' and request.POST.get('action', False): # do confirmed action if request.POST.get('job_ids', False): job_ids = request.POST.getlist('job_ids') if request.POST['action'] == 'delete': for job_id in job_ids: job = Job.fetch(job_id, connection=queue.connection) # Remove job id from queue and delete the actual job queue.connection.lrem(queue.key, 0, job.id) job.delete() messages.info(request, 'You have successfully deleted %s jobs!' % len(job_ids)) elif request.POST['action'] == 'requeue': for job_id in job_ids: requeue_job(job_id, connection=queue.connection) messages.info(request, 'You have successfully requeued %d jobs!' % len(job_ids)) return redirect(next_url)
def check_failed(): """Check the jobs that have failed and requeue them.""" from rq import Queue, get_failed_queue, requeue_job from pybossa.core import sentinel fq = get_failed_queue() job_ids = fq.job_ids count = len(job_ids) FAILED_JOBS_RETRIES = current_app.config.get('FAILED_JOBS_RETRIES') for job_id in job_ids: KEY = 'pybossa:job:failed:%s' % job_id job = fq.fetch_job(job_id) if sentinel.slave.exists(KEY): sentinel.master.incr(KEY) else: ttl = current_app.config.get('FAILED_JOBS_MAILS')*24*60*60 sentinel.master.setex(KEY, ttl, 1) if int(sentinel.slave.get(KEY)) < FAILED_JOBS_RETRIES: requeue_job(job_id) else: KEY = 'pybossa:job:failed:mailed:%s' % job_id if (not sentinel.slave.exists(KEY) and current_app.config.get('ADMINS')): subject = "JOB: %s has failed more than 3 times" % job_id body = "Please, review the background jobs of your server." body += "\n This is the trace error\n\n" body += "------------------------------\n\n" body += job.exc_info mail_dict = dict(recipients=current_app.config.get('ADMINS'), subject=subject, body=body) send_mail(mail_dict) ttl = current_app.config.get('FAILED_JOBS_MAILS')*24*60*60 sentinel.master.setex(KEY, ttl, True) if count > 0: return "JOBS: %s You have failed the system." % job_ids else: return "You have not failed the system"
def requeue_job_view(job_id): requeue_job(job_id) return dict(status='OK')
def requeue(self, cursor, uid, ids, context=None): if not context: context = {} if 'jid' in context: requeue_job(context['jid']) return True
async def requeue_job_view(request, job_id): requeue_job(job_id, connection=current_app.redis_conn) return json(dict(status="OK"))
## get members of our target queue ## # inspect failed jobs for entry in members: assert type(entry) == str print u'- entry is: %s' % unicode( entry ) job_id = u'rq:job:%s' % unicode( entry ) print u'- job_id is: %s' % job_id # ensure failed-job really exists if rds.type( job_id ) == u'none': # job was already deleted (i.e. via interactive redis-cli experimentation), so remove it from failed-queue-list rds.lrem( FAILED_QUEUE_NAME, entry, num=0 ) # note count and value-name are reversed from redis-cli syntax... redis-cli: lrem "rq:queue:failed" 0 "06d0a46e-21ec-4fd3-92f8-f941f32101c4" # failed-job exists, but is it from our target-queue? elif rds.type( job_id ) == u'hash': info_dict = rds.hgetall( job_id ) print u'- type(info_dict): %s' % type(info_dict) # is this a 'job'? if info_dict[u'origin'] == TARGET_QUEUE: # ok, delete the job, _and_ remove it from the failed-queue-list print u'- to requeue...'; pprint.pprint( info_dict ) rq.requeue_job( entry, connection=rds ) # rds.delete( job_id ) # rds.lrem( FAILED_QUEUE_NAME, entry, num=0 ) print u'- requeue attempt made' else: print u'- job_id "%s" not mine; skipping it' % job_id print u'- length of failed-queue is now: %s' % rds.llen( FAILED_QUEUE_NAME ); print u'--' # end
def requeue_job_view(job_id): requeue_job(job_id, connection=current_app.redis_conn) return dict(status='OK')
def retry_handler(job, exc_type, exception, traceback): if isinstance(exception, APIRateLimitError): requeue_job(job.id, Redis()) return False
def save(self): action = self.cleaned_data if action == 'requeue': requeue_job(self.job.id, connection=self.job.connection) elif action == 'cancel': cancel_job(self.job.id, connection=self.job.connection)
def requeue_rq_job(job_id): assert job_id requeue_job(job_id) return dict(status='OK')