Skip to content

Commit

Permalink
added metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersGM committed Jun 19, 2023
1 parent 63384b5 commit d6e2587
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/good_job/metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
module GoodJob # :nodoc:
class Metrics
attr_accessor :failed_count, :succeeded_count

def increment_failed
self.failed_count += 1
end

def increment_succeeded
self.succeeded_count += 1
end
end
end
11 changes: 11 additions & 0 deletions lib/good_job/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "concurrent/executor/timer_set"
require "concurrent/scheduled_task"
require "concurrent/utility/processor_counter"
require 'good_job/stats'

module GoodJob # :nodoc:
#
Expand Down Expand Up @@ -88,6 +89,7 @@ def initialize(performer, max_threads: nil, max_cache: nil, warm_cache_on_initia
@executor_options[:name] = name

@cleanup_tracker = CleanupTracker.new(cleanup_interval_seconds: cleanup_interval_seconds, cleanup_interval_jobs: cleanup_interval_jobs)
@metrics = ::GoodJob::Metrics.new
create_executor
warm_cache if warm_cache_on_initialize
end
Expand Down Expand Up @@ -203,6 +205,12 @@ def task_observer(time, output, thread_error)
instrument("finished_job_task", { result: output, error: thread_error, time: time })
return unless output

if error
@metrics.increment_failed
else
@metrics.increment_succeeded
end

@cleanup_tracker.increment
if @cleanup_tracker.cleanup?
cleanup
Expand All @@ -222,6 +230,9 @@ def stats
max_cache: @max_cache,
active_cache: cache_count,
available_cache: remaining_cache_count,
succeeded_count: @metrics.succeeded_count,
failed_count: @metrics.failed_count,
total_count: @metrics.succeeded_count + @metrics.failed_count
}
end

Expand Down

0 comments on commit d6e2587

Please sign in to comment.