class ForemanTasks::Dynflow

Class for configuring and preparing the Dynflow runtime environment.

Attributes

world[W]

Public Class Methods

new() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 11
def initialize
  @required = false
end

Public Instance Methods

config() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 15
def config
  @config ||= ForemanTasks::Dynflow::Configuration.new
end
eager_load_actions!() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 106
def eager_load_actions!
  config.eager_load_paths.each do |load_path|
    Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
      unless loaded_paths.include?(file)
        require_dependency file
        loaded_paths << file
      end
    end
  end
  @world.reload! if @world
end
executor!() click to toggle source

Mark that the process is executor. This prevents the remote setting from applying. Needs to be set up before the world is being initialized

# File lib/foreman_tasks/dynflow.rb, line 62
def executor!
  @executor = true
end
executor?() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 66
def executor?
  @executor
end
initialize!() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 32
def initialize!
  return unless @required
  return @world if @world

  if config.lazy_initialization && defined?(PhusionPassenger)
    config.dynflow_logger.warn('ForemanTasks: lazy loading with PhusionPassenger might lead to unexpected results')
  end
  config.initialize_world.tap do |world|
    @world = world

    unless config.remote?
      # don't try to do any rescuing until the tables are properly migrated
      if !Foreman.in_rake?('db:migrate') && (begin
                                               ForemanTasks::Task.table_exists?
                                             rescue
                                               (false)
                                             end)
        config.run_on_init_hooks(world)
        # leave this just for long-running executors
        unless config.rake_task_with_executor?
          world.auto_execute
          ForemanTasks::Task::DynflowTask.consistency_check
        end
      end
    end
  end
end
initialized?() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 28
def initialized?
  !@world.nil?
end
loaded_paths() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 118
def loaded_paths
  @loaded_paths ||= Set.new
end
reinitialize!() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 70
def reinitialize!
  @world = nil
  initialize!
end
require!() click to toggle source

call this method if your engine uses Dynflow

# File lib/foreman_tasks/dynflow.rb, line 20
def require!
  @required = true
end
required?() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 24
def required?
  @required
end
web_console() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 90
def web_console
  ::Dynflow::Web.setup do
    before do
      if !Setting[:dynflow_enable_console] ||
         (Setting[:dynflow_console_require_auth] && !ConsoleAuthorizer.new(env).allow?)
        halt 403, 'Access forbidden'
      end
    end

    set(:custom_navigation) do
      { _('Back to tasks') => "/#{ForemanTasks::TasksController.controller_path}" }
    end
    set(:world) { ForemanTasks.dynflow.world }
  end
end
world() click to toggle source
# File lib/foreman_tasks/dynflow.rb, line 75
def world
  return @world if @world

  initialize! if config.lazy_initialization
  unless @world
    raise 'The Dynflow world was not initialized yet. '               'If your plugin uses it, make sure to call ForemanTasks.dynflow.require! '               'in some initializer'
  end

  @world
end