Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap polling within instrumentation #312

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 15 additions & 0 deletions test/integration/instrumentation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading