Skip to content

Commit

Permalink
Use a module level setting
Browse files Browse the repository at this point in the history
  • Loading branch information
djmb committed Nov 8, 2023
1 parent dcc61d9 commit 970f9ed
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
6 changes: 6 additions & 0 deletions lib/solid_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions lib/solid_queue/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def runners
def workers
if mode.in? %i[ work all]
workers_options.flat_map do |worker_options|
worker_options = { silence_polling: silence_polling? }.merge(worker_options)
processes = worker_options.fetch(:processes, WORKER_DEFAULTS[:processes])
processes.times.collect { SolidQueue::Worker.new(**worker_options.with_defaults(WORKER_DEFAULTS)) }
end
Expand All @@ -50,10 +49,6 @@ def max_number_of_threads
workers_options.map { |options| options[:threads] }.max + 2
end

def silence_polling?
@raw_config[:silence_polling].present?
end

private
attr_reader :raw_config, :mode

Expand Down
1 change: 1 addition & 0 deletions lib/solid_queue/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions lib/solid_queue/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ def initialize(**options)
@polling_interval = options[:polling_interval]
@queues = options[:queues]
@pool = Pool.new(options[:threads], on_idle: -> { wake_up })
@silence_polling = options[:silence_polling]
end

def silence_polling?
@silence_polling
end

private
Expand Down Expand Up @@ -53,7 +48,7 @@ def metadata
end

def with_polling_volume
if silence_polling?
if SolidQueue.silence_polling?
ActiveRecord::Base.logger.silence { yield }
else
yield
Expand Down
8 changes: 0 additions & 8 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ class ConfigurationTest < ActiveSupport::TestCase
assert 7, configuration.max_number_of_threads
end

test "silence polling" do
background_worker = { queues: "background", polling_interval: 10 }
config_as_hash = { workers: [ background_worker, background_worker ], silence_polling: true }
configuration = SolidQueue::Configuration.new(mode: :all, load_from: config_as_hash)
assert configuration.silence_polling?
assert configuration.workers.map(&:silence_polling?).all?
end

test "mulitple workers with the same configuration" do
background_worker = { queues: "background", polling_interval: 10, processes: 3 }
config_as_hash = { workers: [ background_worker ] }
Expand Down
7 changes: 5 additions & 2 deletions test/unit/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,28 @@ class WorkerTest < ActiveSupport::TestCase
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
@worker = SolidQueue::Worker.new(queues: "background", threads: 3, polling_interval: 4, silence_polling: true)

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

0 comments on commit 970f9ed

Please sign in to comment.