Class: RogIQ::Commands::Jobs
- Defined in:
- lib/rogiq/commands/jobs.rb
Instance Method Summary collapse
- #detail(id) ⇒ Object
- #discard_one(id) ⇒ Object
- #list ⇒ Object
- #retry_one(id) ⇒ Object
- #tail ⇒ Object
Instance Method Details
#detail(id) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rogiq/commands/jobs.rb', line 46 def detail(id) RogIQ.load_rails! fe = find_failed_execution(id) unless fe fmt.error_msg("Failed execution not found for id=#{id}") exit 1 end job = fe.job payload = { failed_execution_id: fe.id, job_id: job&.id, class_name: job&.class_name, queue_name: job&.queue_name, created_at: job&.created_at, error: fe.error, arguments: job&.arguments } fmt.output(payload) end |
#discard_one(id) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rogiq/commands/jobs.rb', line 83 def discard_one(id) RogIQ.load_rails! fe = find_failed_execution(id) unless fe fmt.error_msg("Failed execution not found for id=#{id}") exit 1 end unless fmt.confirm!("Discard failed execution #{fe.id} (job #{fe.job_id})?", yes: [:yes]) fmt.warn_msg("Aborted.") return end fe.discard fmt.success("Discarded.") end |
#list ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rogiq/commands/jobs.rb', line 10 def list RogIQ.load_rails! unless ActiveRecord::Base.connection.data_source_exists?("solid_queue_jobs") fmt.error_msg("solid_queue tables not present") exit 1 end if [:failed] scope = SolidQueue::FailedExecution.joins(:job).order("solid_queue_failed_executions.id DESC") scope = scope.where(solid_queue_jobs: { class_name: [:class] }) if [:class].present? rows = scope.limit([:limit]).map do |fe| job = fe.job msg = fe.error.is_a?(Hash) ? fe.error["message"] : fe.error.to_s [fe.id, job&.class_name, msg.to_s.truncate(80)] end fmt.output(headers: %w[failed_execution_id class_name error_preview], rows: rows) else unfinished = SolidQueue::Job.where(finished_at: nil).group(:class_name).count.sort_by { |_, n| -n } fmt.output( headers: %w[class_name unfinished_count], rows: unfinished ) fmt.say("") unless [:quiet] fmt.output( { ready: SolidQueue::ReadyExecution.count, scheduled: SolidQueue::ScheduledExecution.count, failed: SolidQueue::FailedExecution.count, claimed: SolidQueue::ClaimedExecution.count } ) end end |
#retry_one(id) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rogiq/commands/jobs.rb', line 69 def retry_one(id) RogIQ.load_rails! fe = find_failed_execution(id) unless fe fmt.error_msg("Failed execution not found for id=#{id}") exit 1 end fe.retry fmt.success("Retried job #{fe.job_id}") end |
#tail ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rogiq/commands/jobs.rb', line 102 def tail RogIQ.load_rails! last_id = SolidQueue::FailedExecution.maximum(:id).to_i fmt.success("Watching SolidQueue::FailedExecution after id=#{last_id}…") loop do sleep [:interval] rows = SolidQueue::FailedExecution.where("id > ?", last_id).order(:id) rows.each do |fe| last_id = fe.id job = fe.job msg = fe.error.is_a?(Hash) ? fe.error["message"] : fe.error fmt.say("[#{fe.id}] #{job&.class_name}: #{msg}") end end end |