Class: Legion::Extensions::Actors::Every

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/legion/extensions/actors/every.rb

Instance Method Summary collapse

Methods included from Base

#args, #check_subtask?, #enabled?, #function, #generate_task?, #manual, #runner, #use_runner?

Methods included from Helpers::Lex

#default_settings, #function_desc, #function_example, #function_options, #function_set, included, #runner_desc

Methods included from Helpers::Logger

#handle_exception, #log

Methods included from Helpers::Core

#find_setting, #settings

Methods included from Helpers::Base

#actor_class, #actor_const, #actor_name, #calling_class, #calling_class_array, #from_json, #full_path, #lex_class, #lex_const, #lex_name, #normalize, #runner_class, #runner_const, #runner_name, #to_dotted_hash

Constructor Details

#initialize(**_opts) ⇒ Every

Returns a new instance of Every.



9
10
11
12
13
14
15
16
17
18
# File 'lib/legion/extensions/actors/every.rb', line 9

def initialize(**_opts)
  @timer = Concurrent::TimerTask.new(execution_interval: time, timeout_interval: timeout, run_now: run_now?) do
    use_runner? ? runner : manual
  end

  @timer.execute
rescue StandardError => e
  Legion::Logging.error e.message
  Legion::Logging.error e.backtrace
end

Instance Method Details

#action(**_opts) ⇒ Object



32
33
34
# File 'lib/legion/extensions/actors/every.rb', line 32

def action(**_opts)
  Legion::Logging.warn 'An extension is using the default block from Legion::Extensions::Runners::Every'
end

#cancelObject



36
37
38
39
40
41
42
43
44
# File 'lib/legion/extensions/actors/every.rb', line 36

def cancel
  Legion::Logging.debug 'Cancelling Legion Timer'
  return true unless @timer.respond_to?(:shutdown)

  @timer.shutdown
rescue StandardError => e
  Legion::Logging.error e.message
  Legion::Logging.error e.backtrace
end

#run_now?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/legion/extensions/actors/every.rb', line 28

def run_now?
  false
end

#timeObject



20
21
22
# File 'lib/legion/extensions/actors/every.rb', line 20

def time
  1
end

#timeoutObject



24
25
26
# File 'lib/legion/extensions/actors/every.rb', line 24

def timeout
  5
end