Class: StatusCat::Checkers::DelayedJob

Inherits:
Base
  • Object
show all
Includes:
ActionView::Helpers::DateHelper
Defined in:
lib/status_cat/checkers/delayed_job.rb

Constant Summary

Constants inherited from Base

Base::FORMAT

Instance Attribute Summary

Attributes inherited from Base

#status, #value

Instance Method Summary collapse

Methods inherited from Base

class_to_name, #name, #to_s

Constructor Details

#initializeDelayedJob

Returns a new instance of DelayedJob.



7
8
9
10
# File 'lib/status_cat/checkers/delayed_job.rb', line 7

def initialize
  return if gem_missing?('delayed_job', defined?(::Delayed))
  @status = fail_on_exception { test }
end

Instance Method Details

#count_expired(expires) ⇒ Object



26
27
28
29
30
# File 'lib/status_cat/checkers/delayed_job.rb', line 26

def count_expired(expires)
  sql = "select count(*) from delayed_jobs where created_at < '#{expires.to_s(:db)}' and failed_at is null"
  result = ::ActiveRecord::Base.connection.execute(sql).first
  return result.is_a?(Hash) ? result['count'] : result[0]
end

#count_jobsObject



20
21
22
23
24
# File 'lib/status_cat/checkers/delayed_job.rb', line 20

def count_jobs
  sql = 'select count(*) from delayed_jobs where failed_at is null'
  result = ::ActiveRecord::Base.connection.execute(sql).first
  return result.is_a?(Hash) ? result['count'] : result[0]
end

#testObject



12
13
14
15
16
17
18
# File 'lib/status_cat/checkers/delayed_job.rb', line 12

def test
  @value = count_jobs

  expires = 1.day.ago
  expired = count_expired(expires)
  expired.zero? ? nil : "#{expired} jobs more than #{time_ago_in_words(expires)} old"
end