diff --git a/lib/good_job/scheduler.rb b/lib/good_job/scheduler.rb index 500f2d150..c8e301e65 100644 --- a/lib/good_job/scheduler.rb +++ b/lib/good_job/scheduler.rb @@ -76,6 +76,12 @@ def initialize(performer, max_threads: nil, max_cache: nil, warm_cache_on_initia self.class.instances << self + @id = SecureRandom.uuid + + source = ActiveSupport::BacktraceCleaner.new.clean(caller.lazy.reject { |line| line.include? File.expand_path(File.dirname(__FILE__)) }).first + puts "\nCreated GoodJob::Scheduler `#{@id}`" + puts "↳ #{source}" + @performer = performer @max_cache = max_cache || 0 @@ -84,7 +90,7 @@ def initialize(performer, max_threads: nil, max_cache: nil, warm_cache_on_initia @executor_options[:max_threads] = max_threads @executor_options[:max_queue] = max_threads end - @name = "GoodJob::Scheduler(queues=#{@performer.name} max_threads=#{@executor_options[:max_threads]})" + @name = "GoodJob::Scheduler(id=#{@id} queues=#{@performer.name} max_threads=#{@executor_options[:max_threads]})" @executor_options[:name] = name @cleanup_tracker = CleanupTracker.new(cleanup_interval_seconds: cleanup_interval_seconds, cleanup_interval_jobs: cleanup_interval_jobs) diff --git a/spec/lib/good_job/capsule_spec.rb b/spec/lib/good_job/capsule_spec.rb index b07bd96d1..97ec8ae8d 100644 --- a/spec/lib/good_job/capsule_spec.rb +++ b/spec/lib/good_job/capsule_spec.rb @@ -24,7 +24,7 @@ capsule = described_class.new Array.new(100) { Thread.new { capsule.start } }.each(&:join) capsule.shutdown - expect(GoodJob::Scheduler.instances.size).to eq 1 + expect(GoodJob::Scheduler.instances.size).to eq(1), "Found more than 1 scheduler instance: #{GoodJob::Scheduler.instances.map(&:name).join(", ")}" end end diff --git a/spec/lib/good_job/scheduler_spec.rb b/spec/lib/good_job/scheduler_spec.rb index 8bdec7b7c..99c940ffe 100644 --- a/spec/lib/good_job/scheduler_spec.rb +++ b/spec/lib/good_job/scheduler_spec.rb @@ -10,8 +10,9 @@ describe 'name' do it 'is human readable and contains configuration values' do + allow(SecureRandom).to receive(:uuid).and_return('1234') scheduler = described_class.new(performer) - expect(scheduler.name).to eq('GoodJob::Scheduler(queues= max_threads=5)') + expect(scheduler.name).to eq("GoodJob::Scheduler(id=1234 queues= max_threads=5)") end end diff --git a/spec/support/reset_good_job.rb b/spec/support/reset_good_job.rb index 98e3d51bb..61210b71d 100644 --- a/spec/support/reset_good_job.rb +++ b/spec/support/reset_good_job.rb @@ -13,7 +13,7 @@ THREAD_ERRORS.clear Thread.current.name = "RSpec: #{example.description}" GoodJob.on_thread_error = lambda do |exception| - THREAD_ERRORS << [Thread.current.name, exception, exception.backtrace] + THREAD_ERRORS << [Thread.current.name, Thread.current.status, exception, exception.backtrace] end example.run