From 32f827f1a7517a34dcde38ec7a926fda10dc4ac7 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Thu, 29 Aug 2024 13:02:59 -0400 Subject: [PATCH] Wrap polling within instrumentation --- lib/solid_queue/processes/poller.rb | 10 ++++++---- test/integration/instrumentation_test.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/solid_queue/processes/poller.rb b/lib/solid_queue/processes/poller.rb index 59a755ae..6a88b06d 100644 --- a/lib/solid_queue/processes/poller.rb +++ b/lib/solid_queue/processes/poller.rb @@ -45,10 +45,12 @@ def shutdown end def with_polling_volume - if SolidQueue.silence_polling? && ActiveRecord::Base.logger - ActiveRecord::Base.logger.silence { yield } - else - yield + SolidQueue.instrument(:polling) do + if SolidQueue.silence_polling? && ActiveRecord::Base.logger + ActiveRecord::Base.logger.silence { yield } + else + yield + end end end end diff --git a/test/integration/instrumentation_test.rb b/test/integration/instrumentation_test.rb index 12fa25ef..4e273170 100644 --- a/test/integration/instrumentation_test.rb +++ b/test/integration/instrumentation_test.rb @@ -37,6 +37,21 @@ class InstrumentationTest < ActiveSupport::TestCase assert_event events.first, "claim", process_id: process.id, job_ids: jobs.map(&:id), claimed_job_ids: jobs.map(&:id), size: 3 end + test "polling emits events" do + 3.times { StoreResultJob.perform_later(42) } + + events = subscribed("polling.solid_queue") do + worker = SolidQueue::Worker.new.tap(&:start) + + wait_while_with_timeout!(3.seconds) { SolidQueue::ReadyExecution.any? } + + worker.stop + end + + assert_equal 5, events.size + events.each { |e| assert_event e, "polling" } + end + test "stopping a worker with claimed executions emits release_claimed events" do StoreResultJob.perform_later(42, pause: SolidQueue.shutdown_timeout + 100.second) process = nil