Skip to content

Commit

Permalink
Wrap polling within instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Aug 29, 2024
1 parent 7901a8e commit 7525d3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/solid_queue/processes/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/integration/instrumentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ 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) }
process = nil
jobs = SolidQueue::Job.last(3)

events = subscribed("polling.solid_queue") do
worker = SolidQueue::Worker.new.tap(&:start)

wait_while_with_timeout!(3.seconds) { SolidQueue::ReadyExecution.any? }
process = SolidQueue::Process.last

worker.stop
wait_for_registered_processes(0, timeout: 3.second)
end

assert_equal 5, events.size
assert_event events.last, "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
Expand Down

0 comments on commit 7525d3c

Please sign in to comment.