Class: GoodJob::JobPerformer::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/good_job/job_performer/metrics.rb

Overview

Metrics for the scheduler.

Instance Method Summary collapse

Constructor Details

#initializeMetrics

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_executionsInteger

Increments number of dequeue attempts with no executions.

Returns:

  • (Integer)


34
35
36
# File 'lib/good_job/job_performer/metrics.rb', line 34

def increment_empty_executions
  @empty_executions.increment
end

#increment_errored_executionsInteger

Increments number of failed executions.

Returns:

  • (Integer)


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_executionsInteger

Increments number of succeeded executions.

Returns:

  • (Integer)


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

#resetvoid

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_hHash

All metrics in a Hash.

Returns:

  • (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_atTime?

Last time the queue was checked for jobs.

Returns:

  • (Time, nil)


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_atTime?

Last time a job was executed (started or finished).

Returns:

  • (Time, nil)


40
41
42
# File 'lib/good_job/job_performer/metrics.rb', line 40

def touch_execution_at
  @execution_at = Time.current
end