Class: Fusuma::Plugin::Executors::CommandExecutor
- Defined in:
- lib/fusuma/plugin/executors/command_executor.rb
Overview
Exector plugin
Constant Summary
Constants inherited from Executor
Executor::BASE_ONESHOT_INTERVAL, Executor::BASE_REPEAT_INTERVAL
Instance Method Summary collapse
-
#args_accel(event) ⇒ Float
: (Fusuma::Plugin::Events::Event) -> Float.
-
#executable?(event) ⇒ Boolean
: (Fusuma::Plugin::Events::Event) -> (String | bool).
-
#execute(event) ⇒ Object
: (Fusuma::Plugin::Events::Event) -> void.
-
#execute_keys ⇒ Array<Symbol>
Executor parameter on config.yml.
-
#search_command(event) ⇒ String
: (Fusuma::Plugin::Events::Event) -> String.
Methods inherited from Executor
#enough_interval?, #interval, #update_interval
Methods inherited from Base
#config_index, #config_param_types, #config_params, inherited, plugins, #shutdown
Instance Method Details
#args_accel(event) ⇒ Float
: (Fusuma::Plugin::Events::Event) -> Float
51 52 53 54 |
# File 'lib/fusuma/plugin/executors/command_executor.rb', line 51 def args_accel(event) accel_index = Config::Index.new([*event.record.index.keys, :accel]) (Config.instance.search(accel_index) || 1).to_f end |
#executable?(event) ⇒ Boolean
: (Fusuma::Plugin::Events::Event) -> (String | bool)
34 35 36 37 38 |
# File 'lib/fusuma/plugin/executors/command_executor.rb', line 34 def executable?(event) event.tag.end_with?("_detector") && event.record.type == :index && search_command(event) end |
#execute(event) ⇒ Object
: (Fusuma::Plugin::Events::Event) -> void
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fusuma/plugin/executors/command_executor.rb', line 17 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}") end |
#execute_keys ⇒ Array<Symbol>
Executor parameter on config.yml
12 13 14 |
# File 'lib/fusuma/plugin/executors/command_executor.rb', line 12 def execute_keys [:command] end |
#search_command(event) ⇒ String
: (Fusuma::Plugin::Events::Event) -> String
43 44 45 46 |
# File 'lib/fusuma/plugin/executors/command_executor.rb', line 43 def search_command(event) command_index = Config::Index.new([*event.record.index.keys, :command]) Config.instance.search(command_index) end |