Skip to content

Commit c7caf01

Browse files
committed
Extract Pidfile setup and deletion to a different concern
Also, rename SupervisorTest to ForkSupervisorTest, as that's the one being tested there.
1 parent 256be75 commit c7caf01

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

lib/solid_queue/supervisor/fork_supervisor.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
module SolidQueue
44
class Supervisor::ForkSupervisor < Supervisor
5-
include Signals
6-
7-
before_boot :setup_pidfile
8-
after_shutdown :delete_pidfile
5+
include Signals, Single
96

107
def initialize(*)
118
super
@@ -98,16 +95,6 @@ def replace_fork(pid, status)
9895
end
9996
end
10097

101-
def setup_pidfile
102-
if path = SolidQueue.supervisor_pidfile
103-
@pidfile = Pidfile.new(path).tap(&:setup)
104-
end
105-
end
106-
107-
def delete_pidfile
108-
@pidfile&.delete
109-
end
110-
11198
def all_forks_terminated?
11299
forks.empty?
113100
end

lib/solid_queue/supervisor/single.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
module SolidQueue
4+
class Supervisor
5+
module Single
6+
extend ActiveSupport::Concern
7+
8+
included do
9+
before_boot :setup_pidfile
10+
after_shutdown :delete_pidfile
11+
end
12+
13+
private
14+
def setup_pidfile
15+
if path = SolidQueue.supervisor_pidfile
16+
@pidfile = Pidfile.new(path).tap(&:setup)
17+
end
18+
end
19+
20+
def delete_pidfile
21+
@pidfile&.delete
22+
end
23+
end
24+
end
25+
end

test/unit/supervisor_test.rb renamed to test/unit/fork_supervisor_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "test_helper"
22

3-
class SupervisorTest < ActiveSupport::TestCase
3+
class ForkSupervisorTest < ActiveSupport::TestCase
44
self.use_transactional_tests = false
55

66
setup do

0 commit comments

Comments
 (0)