Class: GoodJob::JobPerformer::Metrics
- Inherits:
-
Object
- Object
- GoodJob::JobPerformer::Metrics
- Defined in:
- lib/good_job/job_performer/metrics.rb
Overview
Metrics for the scheduler.
Instance Method Summary collapse
-
#increment_empty_executions ⇒ Integer
Increments number of dequeue attempts with no executions.
-
#increment_errored_executions ⇒ Integer
Increments number of failed executions.
-
#increment_succeeded_executions ⇒ Integer
Increments number of succeeded executions.
-
#initialize ⇒ Metrics
constructor
A new instance of Metrics.
-
#reset ⇒ void
Reset counters.
-
#to_h ⇒ Hash
All metrics in a Hash.
-
#touch_check_queue_at ⇒ Time?
Last time the queue was checked for jobs.
-
#touch_execution_at ⇒ Time?
Last time a job was executed (started or finished).
Constructor Details
#initialize ⇒ Metrics
Returns a new instance of Metrics.
9 10 11 12 13 14 15 16 |
# File 'lib/good_job/job_performer/metrics.rb', line 9 def initialize @mutex = Mutex.new @empty_executions = Concurrent::AtomicFixnum.new @errored_executions = Concurrent::AtomicFixnum.new @succeeded_executions = Concurrent::AtomicFixnum.new @execution_at = nil @check_queue_at = nil end |
Instance Method Details
#increment_empty_executions ⇒ Integer
Increments number of dequeue attempts with no executions.
34 35 36 |
# File 'lib/good_job/job_performer/metrics.rb', line 34 def increment_empty_executions @empty_executions.increment end |
#increment_errored_executions ⇒ Integer
Increments number of failed executions.
20 21 22 23 |
# File 'lib/good_job/job_performer/metrics.rb', line 20 def increment_errored_executions @execution_at = Time.current @errored_executions.increment end |
#increment_succeeded_executions ⇒ Integer
Increments number of succeeded executions.
27 28 29 30 |
# File 'lib/good_job/job_performer/metrics.rb', line 27 def increment_succeeded_executions @execution_at = Time.current @succeeded_executions.increment end |
#reset ⇒ void
This method returns an undefined value.
Reset counters.
66 67 68 69 70 71 72 |
# File 'lib/good_job/job_performer/metrics.rb', line 66 def reset @empty_executions.value = 0 @errored_executions.value = 0 @succeeded_executions.value = 0 @execution_at = nil @check_queue_at = nil end |
#to_h ⇒ Hash
All metrics in a Hash.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/good_job/job_performer/metrics.rb', line 52 def to_h { empty_executions_count: @empty_executions.value, errored_executions_count: @errored_executions.value, succeeded_executions_count: @succeeded_executions.value, }.tap do |values| values[:total_executions_count] = values[:succeeded_executions_count] + values[:errored_executions_count] values[:execution_at] = @execution_at values[:check_queue_at] = @check_queue_at end end |
#touch_check_queue_at ⇒ Time?
Last time the queue was checked for jobs.
46 47 48 |
# File 'lib/good_job/job_performer/metrics.rb', line 46 def touch_check_queue_at @check_queue_at = Time.current end |
#touch_execution_at ⇒ Time?
Last time a job was executed (started or finished).
40 41 42 |
# File 'lib/good_job/job_performer/metrics.rb', line 40 def touch_execution_at @execution_at = Time.current end |