Module: ForemanTasks
  
  
  
  
  
  
  
      - Extended by:
 
      - Algebrick::Matching, Algebrick::TypeCheck
 
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/foreman_tasks.rb,
  lib/foreman_tasks/engine.rb,
 lib/foreman_tasks/cleaner.rb,
 lib/foreman_tasks/dynflow.rb,
 lib/foreman_tasks/version.rb,
 lib/foreman_tasks/triggers.rb,
 lib/foreman_tasks/task_error.rb,
 app/models/foreman_tasks/link.rb,
 app/models/foreman_tasks/lock.rb,
 app/models/foreman_tasks/task.rb,
 lib/foreman_tasks/test_helpers.rb,
 lib/foreman_tasks/authorizer_ext.rb,
 lib/foreman_tasks/test_extensions.rb,
 app/models/foreman_tasks/task_group.rb,
 app/models/foreman_tasks/triggering.rb,
 lib/foreman_tasks/continuous_output.rb,
 app/models/foreman_tasks/remote_task.rb,
 app/models/foreman_tasks/task/search.rb,
 app/helpers/foreman_tasks/tasks_helper.rb,
 lib/foreman_tasks/dynflow/configuration.rb,
 app/models/foreman_tasks/recurring_logic.rb,
 app/models/foreman_tasks/task/summarizer.rb,
 app/services/foreman_tasks/proxy_selector.rb,
 app/models/foreman_tasks/task/dynflow_task.rb,
 app/models/foreman_tasks/task_group_member.rb,
 lib/foreman_tasks/dynflow/console_authorizer.rb,
 app/controllers/foreman_tasks/react_controller.rb,
 app/controllers/foreman_tasks/tasks_controller.rb,
 app/helpers/foreman_tasks/foreman_tasks_helper.rb,
 app/models/foreman_tasks/task/status_explicator.rb,
 app/models/foreman_tasks/concerns/action_subject.rb,
 app/models/foreman_tasks/tasks_mail_notification.rb,
 app/models/foreman_tasks/concerns/user_extensions.rb,
 app/controllers/foreman_tasks/api/tasks_controller.rb,
 app/models/foreman_tasks/concerns/action_triggering.rb,
 app/models/foreman_tasks/concerns/host_action_subject.rb,
 app/models/foreman_tasks/task/task_cancelled_exception.rb,
 app/controllers/concerns/foreman_tasks/find_tasks_common.rb,
 app/lib/foreman_tasks/concerns/polling_action_extensions.rb,
 app/controllers/foreman_tasks/recurring_logics_controller.rb,
 app/services/foreman_tasks/troubleshooting_help_generator.rb,
 app/controllers/foreman_tasks/concerns/parameters/triggering.rb,
 app/models/foreman_tasks/recurring_logic_cancelled_exception.rb,
 app/controllers/foreman_tasks/api/recurring_logics_controller.rb,
 app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb,
 app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb,
 app/controllers/foreman_tasks/concerns/parameters/recurring_logic.rb
 
  
  
 
Defined Under Namespace
  
    
      Modules: Api, AuthorizerExt, Concerns, FindTasksCommon, ForemanTasksHelper, TaskGroups, TasksHelper, TestExtensions, TestHelpers, Triggers
    
  
    
      Classes: ActionRule, Cleaner, CompositeActionRule, ContinuousOutput, Dynflow, Engine, Link, Lock, ProxySelector, ReactController, RecurringLogic, RecurringLogicCancelledException, RecurringLogicsController, RemoteTask, Task, TaskError, TaskGroup, TaskGroupMember, TasksController, TasksMailNotification, Triggering, TroubleshootingHelpGenerator
    
  
  
    
      Constant Summary
      collapse
    
    
      
        - VERSION =
          
        
 
        '9.2.3'.freeze
 
      
    
  
  
    
      Class Method Summary
      collapse
    
    
      
        - 
  
    
      .async_task(action, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .delay(action, delay_options, *args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .dynflow  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .rails_safe_trigger_task  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .register_scheduled_task(task_class, cronline)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .sync_task(action, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .table_name_prefix  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .trigger(action, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
        - 
  
    
      .trigger_task(async, action, *args, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
 
      
    
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
    Class Method Details
    
      
  
  
    .async_task(action, *args, &block)  ⇒ Object 
  
  
  
  
    
      
50
51
52 
     | 
    
      # File 'lib/foreman_tasks.rb', line 50
def self.async_task(action, *args, &block)
  trigger_task true, action, *args, &block
end 
     | 
  
 
    
      
  
  
    .delay(action, delay_options, *args)  ⇒ Object 
  
  
  
  
    
      
60
61
62
63 
     | 
    
      # File 'lib/foreman_tasks.rb', line 60
def self.delay(action, delay_options, *args)
  result = dynflow.world.delay action, delay_options, *args
  ForemanTasks::Task::DynflowTask.where(:external_id => result.id).first!
end 
     | 
  
 
    
      
    
      
  
  
    .rails_safe_trigger_task  ⇒ Object 
  
  
  
  
    
      
44
45
46
47
48 
     | 
    
      # File 'lib/foreman_tasks.rb', line 44
def self.rails_safe_trigger_task
  ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
    yield
  end
end
     | 
  
 
    
      
  
  
    .register_scheduled_task(task_class, cronline)  ⇒ Object 
  
  
  
  
    
      
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 
     | 
    
      # File 'lib/foreman_tasks.rb', line 65
def self.register_scheduled_task(task_class, cronline)
  ForemanTasks::RecurringLogic.transaction(isolation: :serializable) do
    return if ForemanTasks::RecurringLogic.joins(:tasks)
                                          .where(state: 'active')
                                          .merge(ForemanTasks::Task.where(label: task_class.name))
                                          .exists?
    User.as_anonymous_admin do
      recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
      recurring_logic.save!
      recurring_logic.start(task_class)
    end
  end
rescue ActiveRecord::TransactionIsolationError end
     | 
  
 
    
      
  
  
    .sync_task(action, *args, &block)  ⇒ Object 
  
  
  
  
    
      
54
55
56
57
58 
     | 
    
      # File 'lib/foreman_tasks.rb', line 54
def self.sync_task(action, *args, &block)
  trigger_task(false, action, *args, &block).tap do |task|
    raise TaskError, task if task.execution_plan.error? || task.execution_plan.result == :warning
  end
end
     | 
  
 
    
      
  
  
    .table_name_prefix  ⇒ Object 
  
  
  
  
    
      
197
198
199 
     | 
    
      # File 'lib/foreman_tasks/engine.rb', line 197
def self.table_name_prefix
  'foreman_tasks_'
end 
     | 
  
 
    
      
  
  
    .trigger(action, *args, &block)  ⇒ Object 
  
  
  
  
    
      
19
20
21 
     | 
    
      # File 'lib/foreman_tasks.rb', line 19
def self.trigger(action, *args, &block)
  dynflow.world.trigger action, *args, &block
end 
     | 
  
 
    
      
  
  
    .trigger_task(async, action, *args, &block)  ⇒ Object 
  
  
  
  
    
      
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 
     | 
    
      # File 'lib/foreman_tasks.rb', line 23
def self.trigger_task(async, action, *args, &block)
  rails_safe_trigger_task do
    Match! async, true, false
    match trigger(action, *args, &block),
          (on ::Dynflow::World::PlaningFailed.call(error: ~any) do |error|
            raise error
          end),
          (on ::Dynflow::World::Triggered.call(execution_plan_id: ~any, future: ~any) do |id, finished|
            unless async
              timeout = Setting['foreman_tasks_sync_task_timeout']
              finished.wait(timeout)
              task = ForemanTasks::Task::DynflowTask.where(:external_id => id).first
              if task.nil? || (!task.paused? && task.pending?)
                raise TimeoutError, "The time waiting for task #{task.try(:id)} to finish exceeded the 'foreman_tasks_sync_task_timeout' (#{timeout}s)"
              end
            end
            task || ForemanTasks::Task::DynflowTask.where(:external_id => id).first!
          end)
  end
end
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #use_relative_model_naming  ⇒ Object 
  
  
  
  
    
      
201
202
203 
     | 
    
      # File 'lib/foreman_tasks/engine.rb', line 201
def use_relative_model_naming
  true
end 
     |