diff --git a/lib/solid_queue.rb b/lib/solid_queue.rb index 6f1fa1ad..1dd92ad8 100644 --- a/lib/solid_queue.rb +++ b/lib/solid_queue.rb @@ -27,10 +27,16 @@ module SolidQueue mattr_accessor :shutdown_timeout, default: 5.seconds + mattr_accessor :silence_polling, default: false + mattr_accessor :supervisor_pidfile mattr_accessor :supervisor, default: false def self.supervisor? supervisor end + + def self.silence_polling? + silence_polling + end end diff --git a/lib/solid_queue/engine.rb b/lib/solid_queue/engine.rb index eebef756..4bf3781a 100644 --- a/lib/solid_queue/engine.rb +++ b/lib/solid_queue/engine.rb @@ -13,6 +13,7 @@ class Engine < ::Rails::Engine SolidQueue.process_heartbeat_interval = app.config.solid_queue.process_heartbeat_interval || 60.seconds SolidQueue.process_alive_threshold = app.config.solid_queue.process_alive_threshold || 5.minutes SolidQueue.shutdown_timeout = app.config.solid_queue.shutdown_timeout || 5.seconds + SolidQueue.silence_polling = app.config.solid_queue.silence_polling || false SolidQueue.supervisor_pidfile = app.config.solid_queue.supervisor_pidfile || app.root.join("tmp", "pids", "solid_queue_supervisor.pid") end end diff --git a/lib/solid_queue/worker.rb b/lib/solid_queue/worker.rb index 89b7e761..2529cf2a 100644 --- a/lib/solid_queue/worker.rb +++ b/lib/solid_queue/worker.rb @@ -16,7 +16,9 @@ def initialize(**options) private def run - claimed_executions = SolidQueue::ReadyExecution.claim(queues, pool.idle_threads, process.id) + claimed_executions = with_polling_volume do + SolidQueue::ReadyExecution.claim(queues, pool.idle_threads, process.id) + end if claimed_executions.size > 0 procline "performing #{claimed_executions.count} jobs in #{queues}" @@ -44,5 +46,13 @@ def all_work_completed? def metadata super.merge(queues: queues, thread_pool_size: pool.size, idle_threads: pool.idle_threads, polling_interval: polling_interval) end + + def with_polling_volume + if SolidQueue.silence_polling? + ActiveRecord::Base.logger.silence { yield } + else + yield + end + end end end diff --git a/test/unit/worker_test.rb b/test/unit/worker_test.rb index ba443878..0f5605aa 100644 --- a/test/unit/worker_test.rb +++ b/test/unit/worker_test.rb @@ -5,7 +5,7 @@ class WorkerTest < ActiveSupport::TestCase include ActiveSupport::Testing::MethodCallAssertions setup do - @worker = SolidQueue::Worker.new(queues: "background", threads: 3, polling_interval: 10) + @worker = SolidQueue::Worker.new(queues: "background", threads: 3, polling_interval: 4) end teardown do @@ -52,4 +52,32 @@ class WorkerTest < ActiveSupport::TestCase assert_equal 5, JobResult.where(queue_name: :background, status: "completed", value: :paused).count assert_equal 3, JobResult.where(queue_name: :background, status: "completed", value: :immediate).count end + + test "polling queries are logged" do + log = StringIO.new + old_logger, ActiveRecord::Base.logger = ActiveRecord::Base.logger, ActiveSupport::Logger.new(log) + old_silence_polling, SolidQueue.silence_polling = SolidQueue.silence_polling, false + + @worker.start(mode: :async) + sleep 0.5 + + assert_match /SELECT .* FROM .solid_queue_ready_executions. WHERE \(.solid_queue_ready_executions...queue_name./, log.string + ensure + ActiveRecord::Base.logger = old_logger + SolidQueue.silence_polling = old_silence_polling + end + + test "polling queries can be silenced" do + log = StringIO.new + old_logger, ActiveRecord::Base.logger = ActiveRecord::Base.logger, ActiveSupport::Logger.new(log) + old_silence_polling, SolidQueue.silence_polling = SolidQueue.silence_polling, true + + @worker.start(mode: :async) + sleep 0.5 + + assert_no_match /SELECT .* FROM .solid_queue_ready_executions. WHERE \(.solid_queue_ready_executions...queue_name./, log.string + ensure + ActiveRecord::Base.logger = old_logger + SolidQueue.silence_polling = old_silence_polling + end end