class Fusuma::Plugin::Executors::CommandExecutor

Exector plugin

Public Instance Methods

args_accel(event) click to toggle source

@param event [Event] @return [Float]

# File lib/fusuma/plugin/executors/command_executor.rb, line 47
def args_accel(event)
  accel_index = Config::Index.new([*event.record.index.keys, :accel])
  (Config.search(accel_index) || 1).to_f
end
executable?(event) click to toggle source
# File lib/fusuma/plugin/executors/command_executor.rb, line 32
def executable?(event)
  event.tag.end_with?('_detector') &&
    event.record.type == :index &&
    search_command(event)
end
execute(event) click to toggle source
# File lib/fusuma/plugin/executors/command_executor.rb, line 16
def execute(event)
  command = search_command(event)

  MultiLogger.info(command: command, args: event.record.args)

  accel = args_accel(event)
  additional_env = event.record.args
                        .deep_transform_keys(&:to_s)
                        .deep_transform_values { |v| (v * accel).to_s }

  pid = Process.spawn(additional_env, command.to_s)
  Process.detach(pid)
rescue SystemCallError => e
  MultiLogger.error("#{event.record.index.keys}": e.message.to_s)
end
execute_keys() click to toggle source

Executor parameter on config.yml @return [Array<Symbol>]

# File lib/fusuma/plugin/executors/command_executor.rb, line 12
def execute_keys
  [:command]
end
search_command(event) click to toggle source

@param event [Event] @return [String]

# File lib/fusuma/plugin/executors/command_executor.rb, line 40
def search_command(event)
  command_index = Config::Index.new([*event.record.index.keys, :command])
  Config.search(command_index)
end