Class: ForemanTasks::Dynflow

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_tasks/dynflow.rb

Overview

Class for configuring and preparing the Dynflow runtime environment.

Defined Under Namespace

Classes: Configuration, ConsoleAuthorizer, Daemon, Persistence

Instance Method Summary collapse

Constructor Details

#initializeDynflow

Returns a new instance of Dynflow.



12
13
14
# File 'lib/foreman_tasks/dynflow.rb', line 12

def initialize
  @required = false
end

Instance Method Details

#configObject



16
17
18
# File 'lib/foreman_tasks/dynflow.rb', line 16

def config
  @config ||= ForemanTasks::Dynflow::Configuration.new
end

#eager_load_actions!Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/foreman_tasks/dynflow.rb', line 95

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!Object

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



56
57
58
# File 'lib/foreman_tasks/dynflow.rb', line 56

def executor!
  @executor = true
end

#executor?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/foreman_tasks/dynflow.rb', line 60

def executor?
  @executor
end

#initialize!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/foreman_tasks/dynflow.rb', line 33

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') && (ForemanTasks::Task.table_exists? rescue(false))
        config.run_on_init_hooks(world)
        world.auto_execute
        ForemanTasks::Task::DynflowTask.consistency_check
      end
    end
  end
end

#initialized?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/foreman_tasks/dynflow.rb', line 29

def initialized?
  !@world.nil?
end

#loaded_pathsObject



107
108
109
# File 'lib/foreman_tasks/dynflow.rb', line 107

def loaded_paths
  @loaded_paths ||= Set.new
end

#reinitialize!Object



64
65
66
67
# File 'lib/foreman_tasks/dynflow.rb', line 64

def reinitialize!
  @world = nil
  self.initialize!
end

#require!Object

call this method if your engine uses Dynflow



21
22
23
# File 'lib/foreman_tasks/dynflow.rb', line 21

def require!
  @required = true
end

#required?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/foreman_tasks/dynflow.rb', line 25

def required?
  @required
end

#web_consoleObject



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/foreman_tasks/dynflow.rb', line 82

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(:world) { ForemanTasks.dynflow.world }
  end
end

#worldObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/foreman_tasks/dynflow.rb', line 69

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

  return @world
end