Module: DashingContrib::Jobs::Sidekiq
- Extended by:
- RunnableJob
- Defined in:
- lib/dashing-contrib/jobs/sidekiq.rb
Constant Summary
Constants included
from RunnableJob
RunnableJob::CRITICAL, RunnableJob::OK, RunnableJob::WARNING
Class Method Summary
collapse
metrics, run, validate_state
Class Method Details
.metrics(options) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/dashing-contrib/jobs/sidekiq.rb', line 7
def self.metrics(options)
stats = ::Sidekiq::Stats.new
metrics = [
{ label: 'Processed', value: stats.processed },
{ label: 'Failed', value: stats.failed },
{ label: 'Retries', value: stats.retry_size },
{ label: 'Dead', value: stats.dead_size },
{ label: 'Enqueued', value: stats.enqueued }
]
{ metrics: metrics }
end
|
.validate_state(metrics, options = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/dashing-contrib/jobs/sidekiq.rb', line 19
def self.validate_state(metrics, options = {})
default = { failed_warning_at: 100, failed_critical_at: 1000 }
user_options = default.merge(options)
failed_stats = metrics[:metrics].select { |v| v[:label] == 'Failed' }.first
value = failed_stats[:value]
return DashingContrib::RunnableJob::OK if value < user_options[:failed_warning_at]
return DashingContrib::RunnableJob::WARNING if value >= user_options[:failed_warning_at] && value < user_options[:failed_critical_at]
DashingContrib::RunnableJob::CRITICAL
end
|