Class: Legion::Extensions::Actors::Once

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/legion/extensions/actors/once.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

#initializeOnce

Returns a new instance of Once.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/legion/extensions/actors/once.rb', line 9

def initialize
  return unless enabled?

  if respond_to? :functions
    functions.each do
      function
      @task = Concurrent::ScheduledTask.execute(delay) do
        use_runner? ? runner : manual
      end
    end
  else
    @task = Concurrent::ScheduledTask.execute(delay) do
      use_runner? ? runner : manual
    end
  end
rescue StandardError => e
  Legion::Logging.error e
end

Instance Method Details

#cancelObject



32
33
34
35
36
# File 'lib/legion/extensions/actors/once.rb', line 32

def cancel
  return unless enabled?

  @task.cancel unless @task.cancelled?
end

#delayObject



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

def delay
  1.0
end