Class: SidekiqMonitoring::Worker

Inherits:
Object
  • Object
show all
Includes:
StatusMixin
Defined in:
lib/sidekiq-monitoring.rb

Constant Summary collapse

DEFAULT_ELAPSED_THRESHOLD =
[ 60, 120 ]

Instance Attribute Summary collapse

Attributes included from StatusMixin

#status

Instance Method Summary collapse

Methods included from StatusMixin

#<=>, #criticality

Constructor Details

#initialize(process_id, jid, run_at, queue, worker_class, elapsed_thresholds = nil) ⇒ Worker

Returns a new instance of Worker.



64
65
66
67
68
69
70
71
72
# File 'lib/sidekiq-monitoring.rb', line 64

def initialize(process_id, jid, run_at, queue, worker_class, elapsed_thresholds = nil)
  @process_id = process_id
  @jid = jid
  @run_at = run_at
  @queue = queue
  @worker_class = worker_class
  @elapsed_warning_threshold, @elapsed_critical_threshold = elapsed_thresholds ? elapsed_thresholds : DEFAULT_ELAPSED_THRESHOLD
  @status = monitoring_status
end

Instance Attribute Details

#elapsed_critical_thresholdObject

Returns the value of attribute elapsed_critical_threshold.



62
63
64
# File 'lib/sidekiq-monitoring.rb', line 62

def elapsed_critical_threshold
  @elapsed_critical_threshold
end

#elapsed_warning_thresholdObject

Returns the value of attribute elapsed_warning_threshold.



62
63
64
# File 'lib/sidekiq-monitoring.rb', line 62

def elapsed_warning_threshold
  @elapsed_warning_threshold
end

#jidObject (readonly)

Returns the value of attribute jid.



61
62
63
# File 'lib/sidekiq-monitoring.rb', line 61

def jid
  @jid
end

#process_idObject (readonly)

Returns the value of attribute process_id.



61
62
63
# File 'lib/sidekiq-monitoring.rb', line 61

def process_id
  @process_id
end

#queueObject (readonly)

Returns the value of attribute queue.



61
62
63
# File 'lib/sidekiq-monitoring.rb', line 61

def queue
  @queue
end

#run_atObject (readonly)

Returns the value of attribute run_at.



61
62
63
# File 'lib/sidekiq-monitoring.rb', line 61

def run_at
  @run_at
end

#worker_classObject (readonly)

Returns the value of attribute worker_class.



61
62
63
# File 'lib/sidekiq-monitoring.rb', line 61

def worker_class
  @worker_class
end

Instance Method Details

#as_jsonObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sidekiq-monitoring.rb', line 74

def as_json
  {
    'queue' => queue,
    'jid' => jid,
    'process_id' => process_id,
    'worker_class' => worker_class,
    'status' => status,
    'elapsed_time' => elapsed_time,
    'elapsed_warning_threshold' => elapsed_warning_threshold,
    'elapsed_critical_threshold' => elapsed_critical_threshold
  }
end

#elapsed_timeObject



87
88
89
# File 'lib/sidekiq-monitoring.rb', line 87

def elapsed_time
  @elapsed_time ||= Time.now.to_i - run_at
end

#monitoring_statusObject



91
92
93
94
95
# File 'lib/sidekiq-monitoring.rb', line 91

def monitoring_status
  return 'CRITICAL' if elapsed_time >= elapsed_critical_threshold
  return 'WARNING' if elapsed_time >= elapsed_warning_threshold
  'OK'
end