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

Creates an instance of process and creates empty hash for callbacks
def initialize
  @callbacks = Hash.new { |hsh, key| hsh[key] = [] }
end

def notice_signal(signal)

Other tags:
    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

Other tags:
    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)

Parameters:
  • signal (Symbol) -- type that we want to catch
def trap_signal(signal)
  trap(signal) do
    notice_signal(signal)
    (@callbacks[signal] || []).each(&:call)
  end
end