class Fusuma::Plugin::Inputs::Input

Inherite this base @abstract Subclass and override {#io} to implement

Public Class Methods

select(inputs) click to toggle source

Wait multiple inputs until it becomes readable and read lines with nonblock @param inputs [Array<Input>] @return [Event]

# File lib/fusuma/plugin/inputs/input.rb, line 16
def self.select(inputs)
  ios = IO.select(inputs.map(&:io))
  io = ios&.first&.first

  input = inputs.find { |i| i.io == io }

  begin
    line = io.readline_nonblock("\n").chomp
  rescue EOFError => e
    warn "#{input.class.name}: #{e}"
    warn 'Send SIGKILL to fusuma processes'
    inputs.reject { |i| i == input }.each do |i|
      warn "stop process: #{i.class.name.underscore}"
      Process.kill(:SIGKILL, i.pid)
    end
    exit 1
  rescue StandardError => e
    warn "#{input.class.name}: #{e}"
    exit 1
  end

  input.create_event(record: line)
end

Public Instance Methods

create_event(record: 'dummy input') click to toggle source

@return [Event]

# File lib/fusuma/plugin/inputs/input.rb, line 51
def create_event(record: 'dummy input')
  e = Events::Event.new(tag: tag, record: record)
  MultiLogger.debug(input_event: e)
  e
end
io() click to toggle source

@return [IO]

# File lib/fusuma/plugin/inputs/input.rb, line 46
def io
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end
pid() click to toggle source

@return [Integer]

# File lib/fusuma/plugin/inputs/input.rb, line 41
def pid
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end
tag() click to toggle source
# File lib/fusuma/plugin/inputs/input.rb, line 57
def tag
  self.class.name.split('Inputs::').last.underscore
end