Skip to content

Commit ef5023c

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 ef5023c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
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

0 commit comments

Comments
 (0)