class Karafka::Process
@note There might be only one process - this class is a singleton
Class used to catch signals from ruby Signal class in order to manage Karafka stop
def initialize
def initialize @callbacks = Hash.new { |hsh, key| hsh[key] = [] } end
def notice_signal(signal)
- Note: - We cannot perform logging from trap context, that's why
Parameters:
-
signal
(Symbol
) -- type that we received
def notice_signal(signal) Thread.new do Karafka.monitor.instrument('process.notice_signal', caller: self, signal: signal) end end
def supervise
- Note: - If there are no callbacks, this method will just ignore a given signal that was sent
def supervise HANDLED_SIGNALS.each { |signal| trap_signal(signal) } end
def trap_signal(signal)
-
signal
(Symbol
) -- type that we want to catch
def trap_signal(signal) trap(signal) do notice_signal(signal) (@callbacks[signal] || []).each(&:call) end end