Class: Karafka::Process

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/karafka/process.rb

Overview

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

Constant Summary collapse

HANDLED_SIGNALS =

Signal types that we handle

%i[
  SIGINT SIGQUIT SIGTERM
].freeze

Instance Method Summary collapse

Constructor Details

#initializeProcess

Creates an instance of process and creates empty hash for callbacks



29
30
31
32
# File 'lib/karafka/process.rb', line 29

def initialize
  @callbacks = {}
  HANDLED_SIGNALS.each { |signal| @callbacks[signal] = [] }
end

Instance Method Details

#supervise {|Block| ... } ⇒ Object

Note:

If there are no callbacks, this method will just ignore a given signal that was sent

Method catches all HANDLED_SIGNALS and performs appropriate callbacks (if defined)

Yields:

  • (Block)

    block of code that we want to execute and supervise



37
38
39
40
# File 'lib/karafka/process.rb', line 37

def supervise
  HANDLED_SIGNALS.each { |signal| trap_signal(signal) }
  yield
end