Skip to content

Commit f92a645

Browse files
committed
Replace the last direct calls to Solid Queue's logger
With Active Support notifications.
1 parent 4f89ebb commit f92a645

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

lib/solid_queue/log_subscriber.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,29 @@ def graceful_termination(event)
105105
if event.payload[:shutdown_timeout_exceeded]
106106
warn formatted_event(event, action: "Supervisor wasn't terminated gracefully - shutdown timeout exceeded", **attributes)
107107
else
108-
formatted_event(event, action: "Supervisor terminated gracefully", **attributes)
108+
info formatted_event(event, action: "Supervisor terminated gracefully", **attributes)
109109
end
110110
end
111111

112112
def immediate_termination(event)
113113
info formatted_event(event, action: "Supervisor terminated immediately", **event.payload.slice(:supervisor_pid, :supervised_pids))
114114
end
115115

116+
def unhandled_signal_error(event)
117+
error formatted_event(event, action: "Received unhandled signal", **event.payload.slice(:signal))
118+
end
119+
120+
def replace_fork(event)
121+
status = event.payload[:status]
122+
attributes = event.payload.slice(:pid).merge(status: status.exitstatus, pid_from_status: status.pid)
123+
124+
if replaced_fork = event.payload[:fork]
125+
info formatted_event(event, action: "Replaced #{replaced_fork.kind}", **attributes.merge(hostname: replaced_fork.hostname))
126+
else
127+
warn formatted_event(event, action: "Tried to replace forked process but it had already died", **attributes)
128+
end
129+
end
130+
116131
private
117132
def formatted_event(event, action:, **attributes)
118133
"SolidQueue-#{SolidQueue::VERSION} #{action} (#{event.duration.round(1)}ms) #{formatted_attributes(**attributes)}"

lib/solid_queue/processes/signals.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def handle_signal(signal)
3838
when :QUIT
3939
request_immediate_termination
4040
else
41-
SolidQueue.logger.warn "Received unhandled signal #{signal}"
41+
SolidQueue.instrument :unhandled_signal_error, signal: signal
4242
end
4343
end
4444

lib/solid_queue/supervisor.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ def reap_terminated_forks
152152
end
153153

154154
def replace_fork(pid, status)
155-
if supervised_fork = forks.delete(pid)
156-
SolidQueue.logger.info "[SolidQueue] Restarting fork[#{status.pid}] (status: #{status.exitstatus})"
157-
start_fork(supervised_fork)
158-
else
159-
SolidQueue.logger.info "[SolidQueue] Tried to replace fork[#{pid}] (status: #{status.exitstatus}, fork[#{status.pid}]), but it had already died (status: #{status.exitstatus})"
155+
SolidQueue.instrument(:replace_fork, supervisor_pid: ::Process.pid, pid: pid, status: status) do |payload|
156+
if supervised_fork = forks.delete(pid)
157+
payload[:fork] = supervised_fork
158+
start_fork(supervised_fork)
159+
end
160160
end
161161
end
162162

0 commit comments

Comments
 (0)