Class: SolidQueueDashboard::Decorators::JobsDecorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SolidQueueDashboard::Decorators::JobsDecorator
- Defined in:
- lib/solid_queue_dashboard/decorators/jobs_decorator.rb
Instance Method Summary collapse
- #each ⇒ Object
- #failure_rate ⇒ Object
- #pending ⇒ Object
- #retried ⇒ Object
- #running ⇒ Object
- #scheduled ⇒ Object
- #success ⇒ Object
- #to_a ⇒ Object
- #with_status(status) ⇒ Object
Instance Method Details
#each ⇒ Object
70 71 72 73 74 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 70 def each super do |job| yield JobDecorator.new(job) end end |
#failure_rate ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 59 def failure_rate success_count = success.count retried_count = retried.count failed_count = failed.count total = success_count + retried_count + failed_count return 0 if total.zero? (failed_count + retried_count).to_f / total * 100 end |
#pending ⇒ Object
37 38 39 40 41 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 37 def pending where(finished_at: nil, scheduled_at: ..Time.current) .where.not(id: failed) .where.not(id: running) end |
#retried ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 43 def retried where(finished_at: ..Time.current) .where.not(id: failed) .where( active_job_id: SolidQueue::Job .select(:active_job_id) .group(:active_job_id) .having("COUNT(*) > 1") ) .where.not( id: SolidQueue::Job .select("MAX(id)") .group(:active_job_id) ) end |
#running ⇒ Object
23 24 25 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 23 def running where.associated(:claimed_execution) end |
#scheduled ⇒ Object
33 34 35 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 33 def scheduled where(finished_at: nil, scheduled_at: Time.current..) end |
#success ⇒ Object
27 28 29 30 31 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 27 def success where.not(finished_at: nil) .where.not(id: failed) .where.not(id: retried) end |
#to_a ⇒ Object
76 77 78 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 76 def to_a super.map { |job| JobDecorator.new(job) } end |
#with_status(status) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/solid_queue_dashboard/decorators/jobs_decorator.rb', line 4 def with_status(status) case status.to_sym when Job::RUNNING running when Job::SUCCESS success when Job::FAILED failed when Job::SCHEDULED scheduled when Job::PENDING pending when Job::RETRIED retried else raise "Invalid status: #{status}" end end |