Skip to content

Commit 386250a

Browse files
committed
Move mode checks from Poller to Runnable, where it should live
And make Poller a class that the dispatcher and worker inherit from. It doesn't make sense to have a module there.
1 parent 1ddfcb3 commit 386250a

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

lib/solid_queue/dispatcher.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# frozen_string_literal: true
22

33
module SolidQueue
4-
class Dispatcher < Processes::Base
5-
include Processes::Poller
6-
4+
class Dispatcher < Processes::Poller
75
attr_accessor :batch_size, :concurrency_maintenance, :recurring_schedule
86

97
after_boot :start_concurrency_maintenance, :load_recurring_schedule
@@ -13,10 +11,11 @@ def initialize(**options)
1311
options = options.dup.with_defaults(SolidQueue::Configuration::DISPATCHER_DEFAULTS)
1412

1513
@batch_size = options[:batch_size]
16-
@polling_interval = options[:polling_interval]
1714

1815
@concurrency_maintenance = ConcurrencyMaintenance.new(options[:concurrency_maintenance_interval], options[:batch_size]) if options[:concurrency_maintenance]
1916
@recurring_schedule = RecurringSchedule.new(options[:recurring_tasks])
17+
18+
super(**options)
2019
end
2120

2221
def metadata

lib/solid_queue/processes/poller.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# frozen_string_literal: true
22

33
module SolidQueue::Processes
4-
module Poller
5-
extend ActiveSupport::Concern
6-
4+
class Poller < Base
75
include Runnable
86

9-
included do
10-
attr_accessor :polling_interval
7+
attr_accessor :polling_interval
8+
9+
def initialize(polling_interval:, **options)
10+
@polling_interval = polling_interval
1111
end
1212

1313
def metadata
@@ -16,11 +16,7 @@ def metadata
1616

1717
private
1818
def run
19-
if mode.async?
20-
@thread = Thread.new { start_loop }
21-
else
22-
start_loop
23-
end
19+
start_loop
2420
end
2521

2622
def start_loop

lib/solid_queue/processes/runnable.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ def start
1313
run_callbacks(:boot) { boot }
1414
end
1515

16-
run
16+
if mode.async?
17+
@thread = Thread.new { run }
18+
else
19+
run
20+
end
1721
end
1822

1923
def stop

lib/solid_queue/worker.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# frozen_string_literal: true
22

33
module SolidQueue
4-
class Worker < Processes::Base
5-
include Processes::Poller
6-
4+
class Worker < Processes::Poller
75
attr_accessor :queues, :pool
86

97
def initialize(**options)
108
options = options.dup.with_defaults(SolidQueue::Configuration::WORKER_DEFAULTS)
119

12-
@polling_interval = options[:polling_interval]
1310
@queues = Array(options[:queues])
1411
@pool = Pool.new(options[:threads], on_idle: -> { wake_up })
12+
13+
super(**options)
1514
end
1615

1716
def metadata

0 commit comments

Comments
 (0)