Skip to content

Commit b9db22d

Browse files
committed
Instrument process shutdown and add some more info to replaced fork event
So we at least can tell when it received a SIGKILL or when it exited normally.
1 parent c0b52a5 commit b9db22d

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

lib/solid_queue/log_subscriber.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ def start_process(event)
6161
info formatted_event(event, action: "Started #{process.kind}", **attributes)
6262
end
6363

64+
def shutdown_process(event)
65+
process = event.payload[:process]
66+
67+
attributes = {
68+
pid: process.pid,
69+
hostname: process.hostname
70+
}.merge(process.metadata)
71+
72+
info formatted_event(event, action: "Shut down #{process.kind}", **attributes)
73+
end
74+
6475
def register_process(event)
6576
process_kind = event.payload[:kind]
6677
attributes = event.payload.slice(:pid, :hostname)
@@ -119,10 +130,15 @@ def unhandled_signal_error(event)
119130

120131
def replace_fork(event)
121132
status = event.payload[:status]
122-
attributes = event.payload.slice(:pid).merge(status: status.exitstatus, pid_from_status: status.pid)
133+
attributes = event.payload.slice(:pid).merge \
134+
status: (status.exitstatus || "no exit status set"),
135+
pid_from_status: status.pid,
136+
signaled: status.signaled?,
137+
stopsig: status.stopsig,
138+
termsig: status.termsig
123139

124140
if replaced_fork = event.payload[:fork]
125-
info formatted_event(event, action: "Replaced #{replaced_fork.kind}", **attributes.merge(hostname: replaced_fork.hostname))
141+
info formatted_event(event, action: "Replaced terminated #{replaced_fork.kind}", **attributes.merge(hostname: replaced_fork.hostname))
126142
else
127143
warn formatted_event(event, action: "Tried to replace forked process but it had already died", **attributes)
128144
end

lib/solid_queue/processes/poller.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def start_loop
3434
end
3535
end
3636
ensure
37-
run_callbacks(:shutdown) { shutdown }
37+
SolidQueue.instrument(:shutdown_process, process: self) do
38+
run_callbacks(:shutdown) { shutdown }
39+
end
3840
end
3941

4042
def poll

test/integration/instrumentation_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class InstrumentationTest < ActiveSupport::TestCase
2525
events = subscribed(/release.*_claimed\.solid_queue/) do
2626
worker = SolidQueue::Worker.new.tap(&:start)
2727

28-
wait_while_with_timeout(1.seconds) { SolidQueue::ReadyExecution.any? }
28+
wait_while_with_timeout(3.seconds) { SolidQueue::ReadyExecution.any? }
2929
process = SolidQueue::Process.last
3030

3131
worker.stop
32-
wait_for_registered_processes(0, timeout: 1.second)
32+
wait_for_registered_processes(0, timeout: 3.second)
3333
end
3434

3535
assert_equal 2, events.size
@@ -59,12 +59,12 @@ class InstrumentationTest < ActiveSupport::TestCase
5959

6060
events = subscribed(/(register|deregister)_process\.solid_queue/) do
6161
worker = SolidQueue::Worker.new.tap(&:start)
62-
wait_while_with_timeout(1.seconds) { SolidQueue::ReadyExecution.any? }
62+
wait_while_with_timeout(3.seconds) { SolidQueue::ReadyExecution.any? }
6363

6464
process = SolidQueue::Process.last
6565

6666
worker.stop
67-
wait_for_registered_processes(0, timeout: 1.second)
67+
wait_for_registered_processes(0, timeout: 3.second)
6868
end
6969

7070
assert_equal 2, events.size

0 commit comments

Comments
 (0)