diff --git a/lib/good_job/scheduler.rb b/lib/good_job/scheduler.rb index 500f2d150..b6881202a 100644 --- a/lib/good_job/scheduler.rb +++ b/lib/good_job/scheduler.rb @@ -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: # @@ -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) + @stats = ::GoodJob::Stats.new create_executor warm_cache if warm_cache_on_initialize end @@ -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 + @stats.increment_failed + else + @stats.increment_succeeded + end + @cleanup_tracker.increment if @cleanup_tracker.cleanup? cleanup @@ -222,6 +230,9 @@ def stats max_cache: @max_cache, active_cache: cache_count, available_cache: remaining_cache_count, + succeeded_count: stats.succeeded_count, + failed_count: stats.failed_count, + total_count: stats.succeeded_count + stats.failed_count } end diff --git a/lib/good_job/stats.rb b/lib/good_job/stats.rb new file mode 100644 index 000000000..46da1821e --- /dev/null +++ b/lib/good_job/stats.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +module GoodJob # :nodoc: + class Stats + attr_accessor :failed_count, :succeeded_count + + def increment_failed + self.failed_count += 1 + end + + def increment_succeeded + self.succeeded_count += 1 + end + end +end