Class: Karafka::Process
- Inherits:
-
Object
- Object
- Karafka::Process
- 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
-
#initialize ⇒ Process
constructor
Creates an instance of process and creates empty hash for callbacks.
-
#supervise ⇒ Object
Method catches all HANDLED_SIGNALS and performs appropriate callbacks (if defined).
-
#supervised? ⇒ Boolean
Is the current process supervised and are trap signals installed.
Constructor Details
#initialize ⇒ Process
Creates an instance of process and creates empty hash for callbacks
31 32 33 34 |
# File 'lib/karafka/process.rb', line 31 def initialize @callbacks = Hash.new { |hsh, key| hsh[key] = [] } @supervised = false end |
Instance Method Details
#supervise ⇒ 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)
38 39 40 41 |
# File 'lib/karafka/process.rb', line 38 def supervise HANDLED_SIGNALS.each { |signal| trap_signal(signal) } @supervised = true end |
#supervised? ⇒ Boolean
Is the current process supervised and are trap signals installed
44 45 46 |
# File 'lib/karafka/process.rb', line 44 def supervised? @supervised end |