Skip to content

Commit 53add2a

Browse files
committed
Worker, Scheduler, and Dispatcher now respect active zone
Note that this pins Rails to a version with ActiveSupport::ReplicationCoordinator see basecamp/rails#35
1 parent 6ec4bc8 commit 53add2a

File tree

9 files changed

+265
-58
lines changed

9 files changed

+265
-58
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

44
# Specify your gem's dependencies in solid_queue.gemspec.
55
gemspec
6+
7+
gem "rails", github: "basecamp/rails", branch: "flavorjones/replication-coordinator"

Gemfile.lock

Lines changed: 122 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,129 @@
1-
PATH
2-
remote: .
1+
GIT
2+
remote: https://github.com/basecamp/rails.git
3+
revision: ed57fc7a886571f10657b0322a8846c09ba29d73
4+
branch: flavorjones/replication-coordinator
35
specs:
4-
solid_queue (1.1.5)
5-
activejob (>= 7.1)
6-
activerecord (>= 7.1)
7-
concurrent-ruby (>= 1.3.1)
8-
fugit (~> 1.11.0)
9-
railties (>= 7.1)
10-
thor (~> 1.3.1)
11-
12-
GEM
13-
remote: https://rubygems.org/
14-
specs:
15-
actionpack (7.1.5.1)
16-
actionview (= 7.1.5.1)
17-
activesupport (= 7.1.5.1)
6+
actioncable (8.1.0.alpha)
7+
actionpack (= 8.1.0.alpha)
8+
activesupport (= 8.1.0.alpha)
9+
nio4r (~> 2.0)
10+
websocket-driver (>= 0.6.1)
11+
zeitwerk (~> 2.6)
12+
actionmailbox (8.1.0.alpha)
13+
actionpack (= 8.1.0.alpha)
14+
activejob (= 8.1.0.alpha)
15+
activerecord (= 8.1.0.alpha)
16+
activestorage (= 8.1.0.alpha)
17+
activesupport (= 8.1.0.alpha)
18+
mail (>= 2.8.0)
19+
actionmailer (8.1.0.alpha)
20+
actionpack (= 8.1.0.alpha)
21+
actionview (= 8.1.0.alpha)
22+
activejob (= 8.1.0.alpha)
23+
activesupport (= 8.1.0.alpha)
24+
mail (>= 2.8.0)
25+
rails-dom-testing (~> 2.2)
26+
actionpack (8.1.0.alpha)
27+
actionview (= 8.1.0.alpha)
28+
activesupport (= 8.1.0.alpha)
1829
nokogiri (>= 1.8.5)
19-
racc
2030
rack (>= 2.2.4)
2131
rack-session (>= 1.0.1)
2232
rack-test (>= 0.6.3)
2333
rails-dom-testing (~> 2.2)
2434
rails-html-sanitizer (~> 1.6)
25-
actionview (7.1.5.1)
26-
activesupport (= 7.1.5.1)
35+
useragent (~> 0.16)
36+
actiontext (8.1.0.alpha)
37+
actionpack (= 8.1.0.alpha)
38+
activerecord (= 8.1.0.alpha)
39+
activestorage (= 8.1.0.alpha)
40+
activesupport (= 8.1.0.alpha)
41+
globalid (>= 0.6.0)
42+
nokogiri (>= 1.8.5)
43+
actionview (8.1.0.alpha)
44+
activesupport (= 8.1.0.alpha)
2745
builder (~> 3.1)
2846
erubi (~> 1.11)
2947
rails-dom-testing (~> 2.2)
3048
rails-html-sanitizer (~> 1.6)
31-
activejob (7.1.5.1)
32-
activesupport (= 7.1.5.1)
49+
activejob (8.1.0.alpha)
50+
activesupport (= 8.1.0.alpha)
3351
globalid (>= 0.3.6)
34-
activemodel (7.1.5.1)
35-
activesupport (= 7.1.5.1)
36-
activerecord (7.1.5.1)
37-
activemodel (= 7.1.5.1)
38-
activesupport (= 7.1.5.1)
52+
activemodel (8.1.0.alpha)
53+
activesupport (= 8.1.0.alpha)
54+
activerecord (8.1.0.alpha)
55+
activemodel (= 8.1.0.alpha)
56+
activesupport (= 8.1.0.alpha)
3957
timeout (>= 0.4.0)
40-
activesupport (7.1.5.1)
58+
activestorage (8.1.0.alpha)
59+
actionpack (= 8.1.0.alpha)
60+
activejob (= 8.1.0.alpha)
61+
activerecord (= 8.1.0.alpha)
62+
activesupport (= 8.1.0.alpha)
63+
marcel (~> 1.0)
64+
activesupport (8.1.0.alpha)
4165
base64
4266
benchmark (>= 0.3)
4367
bigdecimal
44-
concurrent-ruby (~> 1.0, >= 1.0.2)
68+
concurrent-ruby (~> 1.0, >= 1.3.1)
4569
connection_pool (>= 2.2.5)
4670
drb
4771
i18n (>= 1.6, < 2)
4872
logger (>= 1.4.2)
4973
minitest (>= 5.1)
50-
mutex_m
5174
securerandom (>= 0.3)
52-
tzinfo (~> 2.0)
75+
tzinfo (~> 2.0, >= 2.0.5)
76+
uri (>= 0.13.1)
77+
rails (8.1.0.alpha)
78+
actioncable (= 8.1.0.alpha)
79+
actionmailbox (= 8.1.0.alpha)
80+
actionmailer (= 8.1.0.alpha)
81+
actionpack (= 8.1.0.alpha)
82+
actiontext (= 8.1.0.alpha)
83+
actionview (= 8.1.0.alpha)
84+
activejob (= 8.1.0.alpha)
85+
activemodel (= 8.1.0.alpha)
86+
activerecord (= 8.1.0.alpha)
87+
activestorage (= 8.1.0.alpha)
88+
activesupport (= 8.1.0.alpha)
89+
bundler (>= 1.15.0)
90+
railties (= 8.1.0.alpha)
91+
railties (8.1.0.alpha)
92+
actionpack (= 8.1.0.alpha)
93+
activesupport (= 8.1.0.alpha)
94+
irb (~> 1.13)
95+
rackup (>= 1.0.0)
96+
rake (>= 12.2)
97+
thor (~> 1.0, >= 1.2.2)
98+
zeitwerk (~> 2.6)
99+
100+
PATH
101+
remote: .
102+
specs:
103+
solid_queue (1.1.5)
104+
activejob (>= 7.1)
105+
activerecord (>= 7.1)
106+
concurrent-ruby (>= 1.3.1)
107+
fugit (~> 1.11.0)
108+
railties (>= 7.1)
109+
thor (~> 1.3.1)
110+
111+
GEM
112+
remote: https://rubygems.org/
113+
specs:
53114
ast (2.4.2)
54-
base64 (0.2.0)
55-
benchmark (0.4.0)
56-
bigdecimal (3.1.9)
115+
base64 (0.3.0)
116+
benchmark (0.4.1)
117+
bigdecimal (3.2.2)
57118
builder (3.3.0)
58119
concurrent-ruby (1.3.4)
59-
connection_pool (2.4.1)
120+
connection_pool (2.5.3)
60121
crass (1.0.6)
61122
date (3.4.1)
62123
debug (1.9.2)
63124
irb (~> 1.10)
64125
reline (>= 0.3.8)
65-
drb (2.2.1)
126+
drb (2.2.3)
66127
erubi (1.13.1)
67128
et-orbi (1.2.11)
68129
tzinfo
@@ -71,7 +132,7 @@ GEM
71132
raabro (~> 1.4)
72133
globalid (1.2.1)
73134
activesupport (>= 6.1)
74-
i18n (1.14.6)
135+
i18n (1.14.7)
75136
concurrent-ruby (~> 1.0)
76137
io-console (0.8.0)
77138
irb (1.14.3)
@@ -83,17 +144,28 @@ GEM
83144
loofah (2.23.1)
84145
crass (~> 1.0.2)
85146
nokogiri (>= 1.12.0)
147+
mail (2.8.1)
148+
mini_mime (>= 0.1.1)
149+
net-imap
150+
net-pop
151+
net-smtp
152+
marcel (1.0.4)
153+
mini_mime (1.1.5)
86154
mini_portile2 (2.8.8)
87155
minitest (5.25.4)
88156
mocha (2.1.0)
89157
ruby2_keywords (>= 0.0.5)
90-
mutex_m (0.3.0)
91158
mysql2 (0.5.6)
159+
net-imap (0.5.8)
160+
date
161+
net-protocol
162+
net-pop (0.1.2)
163+
net-protocol
164+
net-protocol (0.2.2)
165+
timeout
166+
net-smtp (0.5.1)
167+
net-protocol
92168
nio4r (2.7.4)
93-
nokogiri (1.18.0-arm64-darwin)
94-
racc (~> 1.4)
95-
nokogiri (1.18.0-x86_64-darwin)
96-
racc (~> 1.4)
97169
nokogiri (1.18.0-x86_64-linux-gnu)
98170
racc (~> 1.4)
99171
parallel (1.26.3)
@@ -109,7 +181,8 @@ GEM
109181
raabro (1.4.0)
110182
racc (1.8.1)
111183
rack (3.1.8)
112-
rack-session (2.0.0)
184+
rack-session (2.1.1)
185+
base64 (>= 0.1.0)
113186
rack (>= 3.0.0)
114187
rack-test (2.2.0)
115188
rack (>= 1.3)
@@ -122,14 +195,6 @@ GEM
122195
rails-html-sanitizer (1.6.2)
123196
loofah (~> 2.21)
124197
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
125-
railties (7.1.5.1)
126-
actionpack (= 7.1.5.1)
127-
activesupport (= 7.1.5.1)
128-
irb
129-
rackup (>= 1.0.0)
130-
rake (>= 12.2)
131-
thor (~> 1.0, >= 1.2.2)
132-
zeitwerk (~> 2.6)
133198
rainbow (3.1.1)
134199
rake (13.2.1)
135200
rdoc (6.8.1)
@@ -178,6 +243,12 @@ GEM
178243
unicode-display_width (3.1.3)
179244
unicode-emoji (~> 4.0, >= 4.0.4)
180245
unicode-emoji (4.0.4)
246+
uri (1.0.3)
247+
useragent (0.16.11)
248+
websocket-driver (0.8.0)
249+
base64
250+
websocket-extensions (>= 0.1.0)
251+
websocket-extensions (0.1.5)
181252
zeitwerk (2.6.0)
182253

183254
PLATFORMS
@@ -195,6 +266,7 @@ DEPENDENCIES
195266
mysql2
196267
pg
197268
puma
269+
rails!
198270
rdoc
199271
rubocop-rails-omakase
200272
solid_queue!

lib/solid_queue/dispatcher.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
module SolidQueue
44
class Dispatcher < Processes::Poller
55
include LifecycleHooks
6+
include Processes::Standby
7+
68
attr_reader :batch_size
79

810
after_boot :run_start_hooks
9-
after_boot :start_concurrency_maintenance
11+
after_boot do
12+
on_active_zone { start_concurrency_maintenance }
13+
on_active_zone { wake_up }
14+
on_passive_zone { stop_concurrency_maintenance }
15+
end
1016
before_shutdown :stop_concurrency_maintenance
1117
before_shutdown :run_stop_hooks
1218
after_shutdown :run_exit_hooks
@@ -29,9 +35,13 @@ def metadata
2935
attr_reader :concurrency_maintenance
3036

3137
def poll
32-
batch = dispatch_next_batch
38+
if active_zone?
39+
batch = dispatch_next_batch
3340

34-
batch.zero? ? polling_interval : 0.seconds
41+
batch.zero? ? polling_interval : 0.seconds
42+
else
43+
replication_coordinator.polling_interval
44+
end
3545
end
3646

3747
def dispatch_next_batch

lib/solid_queue/processes/standby.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module SolidQueue::Processes
4+
module Standby
5+
extend ActiveSupport::Concern
6+
7+
delegate :on_active_zone, to: :replication_coordinator
8+
delegate :on_passive_zone, to: :replication_coordinator
9+
delegate :active_zone?, to: :replication_coordinator
10+
11+
def replication_coordinator
12+
Rails.application.config.replication_coordinator
13+
end
14+
15+
included do
16+
on_start { |process| process.replication_coordinator.start_monitoring }
17+
on_stop { |process| process.replication_coordinator.stop_monitoring }
18+
end
19+
end
20+
end

lib/solid_queue/scheduler.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ module SolidQueue
44
class Scheduler < Processes::Base
55
include Processes::Runnable
66
include LifecycleHooks
7+
include Processes::Standby
78

89
attr_reader :recurring_schedule
910

1011
after_boot :run_start_hooks
11-
after_boot :schedule_recurring_tasks
12+
after_boot do
13+
on_active_zone { schedule_recurring_tasks }
14+
on_passive_zone { unschedule_recurring_tasks }
15+
end
1216
before_shutdown :unschedule_recurring_tasks
1317
before_shutdown :run_stop_hooks
1418
after_shutdown :run_exit_hooks

lib/solid_queue/worker.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
module SolidQueue
44
class Worker < Processes::Poller
55
include LifecycleHooks
6+
include Processes::Standby
67

78
after_boot :run_start_hooks
9+
after_boot { on_active_zone { wake_up } }
810
before_shutdown :run_stop_hooks
911
after_shutdown :run_exit_hooks
1012

@@ -27,9 +29,13 @@ def metadata
2729

2830
private
2931
def poll
30-
post_executions
32+
if active_zone?
33+
post_executions
3134

32-
pool.idle? ? polling_interval : 10.minutes
35+
pool.idle? ? polling_interval : 10.minutes
36+
else
37+
replication_coordinator.polling_interval
38+
end
3339
end
3440

3541
def post_executions

0 commit comments

Comments
 (0)