Class: Karafka::Process

Inherits:
Object
  • Object
show all
Extended by:
Core::Taggable
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
  SIGTTIN
  SIGTSTP
].freeze

Instance Method Summary collapse

Constructor Details

#initializeProcess

Creates an instance of process and creates empty hash for callbacks



34
35
36
37
# File 'lib/karafka/process.rb', line 34

def initialize
  @callbacks = Hash.new { |hsh, key| hsh[key] = [] }
  @supervised = false
end

Instance Method Details

#superviseObject

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)



41
42
43
44
# File 'lib/karafka/process.rb', line 41

def supervise
  HANDLED_SIGNALS.each { |signal| trap_signal(signal) }
  @supervised = true
end

#supervised?Boolean

Is the current process supervised and are trap signals installed

Returns:

  • (Boolean)


47
48
49
# File 'lib/karafka/process.rb', line 47

def supervised?
  @supervised
end