class Fusuma::Plugin::Executors::Executor

Inherite this base

Constants

BASE_ONESHOT_INTERVAL
BASE_REPEAT_INTERVAL

Public Instance Methods

enough_interval?(event) click to toggle source

@param event [Events::Event] @param time [Time] @return [TrueClass, FalseClass]

# File lib/fusuma/plugin/executors/executor.rb, line 31
def enough_interval?(event)
  # NOTE: Cache at the index that is actually used, reflecting Fallback and Skip.
  #       Otherwise, a wrong index will cause invalid intervals.
  return true if event.record.index.with_context.keys.any? { |key| key.symbol == :end }

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

  true
end
executable?(_event) click to toggle source

check executable @param _event [Events::Event] @return [TrueClass, FalseClass]

# File lib/fusuma/plugin/executors/executor.rb, line 24
def executable?(_event)
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end
execute(_event) click to toggle source

execute something @param _event [Event] @return [nil]

# File lib/fusuma/plugin/executors/executor.rb, line 63
def execute(_event)
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end
execute_keys() click to toggle source

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

# 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) click to toggle source
# File lib/fusuma/plugin/executors/executor.rb, line 45
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) click to toggle source
# File lib/fusuma/plugin/executors/executor.rb, line 41
def update_interval(event)
  @wait_until = event.time + interval(event).to_f
end