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
: (Fusuma::Plugin::Events::Event) -> bool.
-
#executable?(_event) ⇒ TrueClass, FalseClass
check executable : (String) -> nil.
-
#execute(_event) ⇒ nil
execute something : (String) -> nil.
-
#execute_keys ⇒ Array<Symbol>
Executor parameter on config.yml : () -> nil.
-
#interval(event) ⇒ Object
: (Fusuma::Plugin::Events::Event) -> Float.
-
#update_interval(event) ⇒ Object
: (Fusuma::Plugin::Events::Event) -> Time.
Methods inherited from Base
#config_index, #config_param_types, #config_params, inherited, plugins, #shutdown
Instance Method Details
#enough_interval?(event) ⇒ TrueClass, FalseClass
: (Fusuma::Plugin::Events::Event) -> bool
33 34 35 36 37 38 39 |
# File 'lib/fusuma/plugin/executors/executor.rb', line 33 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 : (String) -> nil
26 27 28 |
# File 'lib/fusuma/plugin/executors/executor.rb', line 26 def executable?(_event) raise NotImplementedError, "override #{self.class.name}##{__method__}" end |
#execute(_event) ⇒ nil
execute something : (String) -> nil
66 67 68 |
# File 'lib/fusuma/plugin/executors/executor.rb', line 66 def execute(_event) raise NotImplementedError, "override #{self.class.name}##{__method__}" end |
#execute_keys ⇒ Array<Symbol>
Executor parameter on config.yml : () -> nil
17 18 19 20 |
# File 'lib/fusuma/plugin/executors/executor.rb', line 17 def execute_keys # [name.split('Executors::').last.underscore.gsub('_executor', '').to_sym] raise NotImplementedError, "override #{self.class.name}##{__method__}" end |
#interval(event) ⇒ Object
: (Fusuma::Plugin::Events::Event) -> Float
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fusuma/plugin/executors/executor.rb', line 47 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
: (Fusuma::Plugin::Events::Event) -> Time
42 43 44 |
# File 'lib/fusuma/plugin/executors/executor.rb', line 42 def update_interval(event) @wait_until = event.time + interval(event).to_f end |