Class: Fusuma::Plugin::Executors::Executor
- Defined in:
- lib/fusuma/plugin/executors/executor.rb
Overview
Inherite this base
Direct Known Subclasses
Constant Summary collapse
- BASE_ONESHOT_INTERVAL =
0.3
- BASE_REPEAT_INTERVAL =
0.1
Instance Method Summary collapse
- #enough_interval?(event) ⇒ TrueClass, FalseClass
-
#executable?(_event) ⇒ TrueClass, FalseClass
check executable.
-
#execute(_event) ⇒ nil
execute something.
-
#execute_keys ⇒ Array<Symbol>
Executor parameter on config.yml.
- #interval(event) ⇒ Object
- #update_interval(event) ⇒ Object
Methods inherited from Base
#config_index, #config_param_types, #config_params, inherited, plugins, #shutdown
Instance Method Details
#enough_interval?(event) ⇒ 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
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
60 61 62 |
# File 'lib/fusuma/plugin/executors/executor.rb', line 60 def execute(_event) raise NotImplementedError, "override #{self.class.name}##{__method__}" end |
#execute_keys ⇒ Array<Symbol>
Executor parameter on config.yml
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 |