Class: Ragdoll::JobsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Ragdoll::JobsController
- Defined in:
- app/controllers/ragdoll/jobs_controller.rb
Instance Method Summary collapse
- #bulk_delete ⇒ Object
- #bulk_retry ⇒ Object
- #cancel_all_pending ⇒ Object
- #destroy ⇒ Object
- #health ⇒ Object
- #index ⇒ Object
- #restart_workers ⇒ Object
- #retry ⇒ Object
- #show ⇒ Object
Instance Method Details
#bulk_delete ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 64 def bulk_delete job_ids = params[:job_ids] || [] job_type = params[:job_type] || 'pending' deleted_count = 0 job_ids.each do |job_id| begin if job_type == 'failed' SolidQueue::FailedExecution.find(job_id).destroy else SolidQueue::Job.find(job_id).destroy end deleted_count += 1 rescue => e Rails.logger.error "Failed to delete job #{job_id}: #{e.message}" end end redirect_to ragdoll.jobs_path, notice: "Successfully deleted #{deleted_count} job(s)." rescue => e redirect_to ragdoll.jobs_path, alert: "Bulk delete failed: #{e.message}" end |
#bulk_retry ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 88 def bulk_retry job_ids = params[:job_ids] || [] retried_count = 0 job_ids.each do |job_id| begin failed_execution = SolidQueue::FailedExecution.find(job_id) failed_execution.retry retried_count += 1 rescue => e Rails.logger.error "Failed to retry job #{job_id}: #{e.message}" end end redirect_to ragdoll.jobs_path, notice: "Successfully retried #{retried_count} job(s)." rescue => e redirect_to ragdoll.jobs_path, alert: "Bulk retry failed: #{e.message}" end |
#cancel_all_pending ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 107 def cancel_all_pending begin deleted_count = SolidQueue::Job.where(finished_at: nil).delete_all redirect_to ragdoll.jobs_path, notice: "Successfully canceled #{deleted_count} pending job(s)." rescue => e redirect_to ragdoll.jobs_path, alert: "Failed to cancel all pending jobs: #{e.message}" end end |
#destroy ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 32 def destroy if params[:type] == 'failed' SolidQueue::FailedExecution.find(params[:id]).destroy else SolidQueue::Job.find(params[:id]).destroy end redirect_to ragdoll.jobs_path, notice: 'Job deleted successfully' rescue => e redirect_to ragdoll.jobs_path, alert: "Failed to delete job: #{e.message}" end |
#health ⇒ Object
43 44 45 46 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 43 def health health_status = WorkerHealthService.check_worker_health render json: health_status end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 7 def index @pending_jobs = SolidQueue::Job.where(finished_at: nil).order(created_at: :desc).limit(50) @completed_jobs = SolidQueue::Job.where.not(finished_at: nil).order(finished_at: :desc).limit(50) @failed_jobs = SolidQueue::FailedExecution.order(created_at: :desc).limit(50) @stats = { pending: SolidQueue::Job.where(finished_at: nil).count, completed: SolidQueue::Job.where.not(finished_at: nil).count, failed: SolidQueue::FailedExecution.count, total: SolidQueue::Job.count } end |
#restart_workers ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 48 def restart_workers if WorkerHealthService.needs_restart? # Process stuck jobs first processed_count = WorkerHealthService.process_stuck_jobs!(10) # Restart workers WorkerHealthService.restart_workers! redirect_to ragdoll.jobs_path, notice: "Workers restarted! Processed #{processed_count} stuck jobs." else redirect_to ragdoll.jobs_path, alert: "Workers appear to be healthy." end rescue => e redirect_to ragdoll.jobs_path, alert: "Failed to restart workers: #{e.message}" end |
#retry ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 24 def retry failed_execution = SolidQueue::FailedExecution.find(params[:id]) failed_execution.retry redirect_to ragdoll.jobs_path, notice: 'Job retried successfully' rescue => e redirect_to ragdoll.jobs_path, alert: "Failed to retry job: #{e.message}" end |
#show ⇒ Object
20 21 22 |
# File 'app/controllers/ragdoll/jobs_controller.rb', line 20 def show @job = SolidQueue::Job.find(params[:id]) end |