Skip to content

Commit 5b1ba0b

Browse files
nashbyrosa
authored andcommitted
Run Supervisor only when puma is fully booted.
1 parent 93cccd9 commit 5b1ba0b

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ GEM
131131
nokogiri (1.15.4-x86_64-linux)
132132
racc (~> 1.4)
133133
pg (1.5.4)
134+
puma (6.4.0)
135+
nio4r (~> 2.0)
134136
racc (1.7.1)
135137
rack (3.0.8)
136138
rack-session (2.0.0)
@@ -194,6 +196,7 @@ DEPENDENCIES
194196
mocha
195197
mysql2
196198
pg
199+
puma
197200
solid_queue!
198201
sqlite3
199202

lib/puma/plugin/solid_queue.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
def start(launcher)
77
@log_writer = launcher.log_writer
88
@puma_pid = $$
9-
@solid_queue_pid = fork do
10-
Thread.new { monitor_puma }
11-
SolidQueue::Supervisor.start(mode: :all)
12-
end
139

14-
launcher.events.on_stopped { stop_solid_queue }
10+
launcher.events.on_booted do
11+
@solid_queue_pid = fork do
12+
Thread.new { monitor_puma }
13+
SolidQueue::Supervisor.start(mode: :all)
14+
end
1515

16-
in_background do
17-
monitor_solid_queue
16+
in_background do
17+
monitor_solid_queue
18+
end
1819
end
20+
21+
launcher.events.on_stopped { stop_solid_queue }
1922
end
2023

2124
private

solid_queue.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
2020
spec.add_dependency "rails", ">= 7.0.3.1"
2121
spec.add_development_dependency "debug"
2222
spec.add_development_dependency "mocha"
23+
spec.add_development_dependency "puma"
2324
end

test/dummy/config/puma.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@
4141

4242
# Allow puma to be restarted by `bin/rails restart` command.
4343
plugin :tmp_restart
44+
plugin :solid_queue

test/integration/puma/plugin_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
require "test_helper"
3+
4+
class PumaPluginTest < ActiveSupport::TestCase
5+
self.use_transactional_tests = false
6+
7+
setup do
8+
cmd = %w[
9+
bundle exec puma
10+
-b tcp://127.0.0.1:9222
11+
-C test/dummy/config/puma.rb
12+
--dir test/dummy
13+
-s
14+
config.ru
15+
]
16+
17+
@pid = fork do
18+
exec(*cmd)
19+
end
20+
end
21+
22+
teardown do
23+
Process.kill :INT, @pid
24+
end
25+
26+
test "perform jobs inside puma's process" do
27+
StoreResultJob.perform_later(:puma_plugin)
28+
29+
wait_for_jobs_to_finish_for(1.second)
30+
assert_equal 1, JobResult.where(queue_name: :background, status: "completed", value: :puma_plugin).count
31+
end
32+
end

0 commit comments

Comments
 (0)