Class: Fusuma::Plugin::Executors::Executor

Inherits:
Base
  • Object
show all
Defined in:
lib/fusuma/plugin/executors/executor.rb

Overview

Inherite this base

Direct Known Subclasses

CommandExecutor

Constant Summary collapse

BASE_ONESHOT_INTERVAL =
0.3
BASE_REPEAT_INTERVAL =
0.1

Instance Method Summary collapse

Methods inherited from Base

#config_index, #config_param_types, #config_params, inherited, plugins, #shutdown

Instance Method Details

#enough_interval?(event) ⇒ TrueClass, FalseClass

Parameters:

Returns:

  • (TrueClass, FalseClass)


30
31
32
33
34
35
36
# File 'lib/fusuma/plugin/executors/executor.rb', line 30

def enough_interval?(event)
  return true if event.record.index.keys.any? { |key| key.symbol == :end }

  return false if @wait_until && event.time < @wait_until

  true
end

#executable?(_event) ⇒ TrueClass, FalseClass

check executable

Parameters:

Returns:

  • (TrueClass, FalseClass)

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/fusuma/plugin/executors/executor.rb', line 24

def executable?(_event)
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end

#execute(_event) ⇒ nil

execute something

Parameters:

  • _event (Event)

Returns:

  • (nil)

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/fusuma/plugin/executors/executor.rb', line 60

def execute(_event)
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end

#execute_keysArray<Symbol>

Executor parameter on config.yml

Returns:

  • (Array<Symbol>)

Raises:

  • (NotImplementedError)


16
17
18
19
# File 'lib/fusuma/plugin/executors/executor.rb', line 16

def execute_keys
  # [name.split('Executors::').last.underscore.gsub('_executor', '').to_sym]
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end

#interval(event) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fusuma/plugin/executors/executor.rb', line 42

def interval(event)
  @interval_time ||= {}
  index = event.record.index
  @interval_time[index.cache_key] ||= begin
    config_value =
      Config.search(Config::Index.new([*index.keys, "interval"])) ||
      Config.search(Config::Index.new(["interval", Detectors::Detector.type(event.tag)]))
    if event.record.trigger == :oneshot
      (config_value || 1) * BASE_ONESHOT_INTERVAL
    else
      (config_value || 1) * BASE_REPEAT_INTERVAL
    end
  end
end

#update_interval(event) ⇒ Object



38
39
40
# File 'lib/fusuma/plugin/executors/executor.rb', line 38

def update_interval(event)
  @wait_until = event.time + interval(event).to_f
end