Class: SidekiqMonitoring::Worker
- Inherits:
-
Object
- Object
- SidekiqMonitoring::Worker
- Includes:
- StatusMixin
- Defined in:
- lib/sidekiq-monitoring.rb
Constant Summary collapse
- DEFAULT_ELAPSED_THRESHOLD =
[ 60, 120 ]
Instance Attribute Summary collapse
-
#elapsed_critical_threshold ⇒ Object
Returns the value of attribute elapsed_critical_threshold.
-
#elapsed_warning_threshold ⇒ Object
Returns the value of attribute elapsed_warning_threshold.
-
#jid ⇒ Object
readonly
Returns the value of attribute jid.
-
#process_id ⇒ Object
readonly
Returns the value of attribute process_id.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#run_at ⇒ Object
readonly
Returns the value of attribute run_at.
-
#worker_class ⇒ Object
readonly
Returns the value of attribute worker_class.
Attributes included from StatusMixin
Instance Method Summary collapse
- #as_json ⇒ Object
- #elapsed_time ⇒ Object
-
#initialize(process_id, jid, run_at, queue, worker_class, elapsed_thresholds = nil) ⇒ Worker
constructor
A new instance of Worker.
- #monitoring_status ⇒ Object
Methods included from StatusMixin
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_threshold ⇒ Object
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_threshold ⇒ Object
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 |
#jid ⇒ Object (readonly)
Returns the value of attribute jid.
61 62 63 |
# File 'lib/sidekiq-monitoring.rb', line 61 def jid @jid end |
#process_id ⇒ Object (readonly)
Returns the value of attribute process_id.
61 62 63 |
# File 'lib/sidekiq-monitoring.rb', line 61 def process_id @process_id end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
61 62 63 |
# File 'lib/sidekiq-monitoring.rb', line 61 def queue @queue end |
#run_at ⇒ Object (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_class ⇒ Object (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_json ⇒ Object
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_time ⇒ Object
87 88 89 |
# File 'lib/sidekiq-monitoring.rb', line 87 def elapsed_time @elapsed_time ||= Time.now.to_i - run_at end |
#monitoring_status ⇒ Object
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 |