Sha256: 43fcc64da4647bf988551f824f801e57b91a7f00df6579788df00fce2aac4a74

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

require 'posix/spawn'
require_relative './executor.rb'

module Fusuma
  module Plugin
    module Executors
      # Exector plugin
      class CommandExecutor < Executor
        def execute(event)
          search_command(event).tap do |command|
            break unless command

            MultiLogger.info(command: command)

            pid = POSIX::Spawn.spawn(command.to_s)
            Process.detach(pid)
          end
        end

        def executable?(event)
          event.tag.end_with?('_detector') &&
            event.record.type == :index &&
            search_command(event)
        end

        # @param event [Event]
        # @return [String]
        def search_command(event)
          command_index = Config::Index.new([*event.record.index.keys, :command])
          Config.search(command_index)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fusuma-2.0.0.pre lib/fusuma/plugin/executors/command_executor.rb