Class: ProcessCommand::BaseReceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/process_command/base_receiver.rb

Direct Known Subclasses

Signal::Receiver, Socket::Receiver

Class Method Summary collapse

Class Method Details

.add_command_block(command, block) ⇒ Object



15
16
17
18
# File 'lib/process_command/base_receiver.rb', line 15

def add_command_block(command, block)
  @command_blocks ||= {}
  @command_blocks[command.to_s] = block
end

.initObject



8
9
10
11
12
13
# File 'lib/process_command/base_receiver.rb', line 8

def init
  init_listener
  Thread.new do
    init_handler
  end
end

.run_command_block(command) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/process_command/base_receiver.rb', line 20

def run_command_block(command)
  command = command.to_s
  block = @command_blocks[command]
  if block
    Thread.new do
      begin
        block.call
      rescue Exception => e
        ProcessCommand.logger.error "block execute error for command (#{command}), error: #{e.message}"
      end
    end
  else
    ProcessCommand.logger.error "block not found for command (#{command})"
  end
end