Class: ForemanTasks::Dynflow::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 30

def initialize
  self.pool_size                = 5
  self.db_pool_size             = pool_size + 5
  self.remote                   = Rails.env.production?
  self.transaction_adapter      = ::Dynflow::TransactionAdapters::ActiveRecord.new
  self.eager_load_paths         = []
  self.lazy_initialization      = !Rails.env.production?
  self.rake_tasks_with_executor = %w[db:migrate db:seed]

  @on_init = []
end

Instance Attribute Details

#db_pool_sizeObject

the size of db connection pool



8
9
10
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 8

def db_pool_size
  @db_pool_size
end

#disable_active_record_actionsObject

if true, the ForemanTasks::Concerns::ActionTriggering will make no effect. Useful for testing, where we mignt not want to execute the orchestration tied to the models.



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

def disable_active_record_actions
  @disable_active_record_actions
end

#eager_load_pathsObject

Returns the value of attribute eager_load_paths.



18
19
20
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 18

def eager_load_paths
  @eager_load_paths
end

#lazy_initializationObject

Returns the value of attribute lazy_initialization.



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

def lazy_initialization
  @lazy_initialization
end

#pool_sizeObject

the number of threads in the pool handling the execution



5
6
7
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 5

def pool_size
  @pool_size
end

#rake_tasks_with_executorObject

what rake tasks should run their own executor, not depending on the external one



23
24
25
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 23

def rake_tasks_with_executor
  @rake_tasks_with_executor
end

#remoteObject Also known as: remote?

set true if the executor runs externally (by default true in procution, othewise false)



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

def remote
  @remote
end

#transaction_adapterObject

what transaction adapater should be used, by default, it uses the ActiveRecord based adapter, expecting ActiveRecord is used as ORM in the application



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

def transaction_adapter
  @transaction_adapter
end

Instance Method Details

#action_loggerObject

for logging action related info (such as exceptions raised in side the actions’ methods



44
45
46
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 44

def action_logger
  Foreman::Logging.logger('foreman-tasks/action')
end

#dynflow_loggerObject

for logging dynflow related info about the progress of the execution etc.



49
50
51
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 49

def dynflow_logger
  Foreman::Logging.logger('foreman-tasks/dynflow')
end

#increase_db_pool_sizeObject

To avoid pottential timeouts on db connection pool, make sure we have the pool bigger than the thread pool



87
88
89
90
91
92
93
94
95
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 87

def increase_db_pool_size
  if increase_db_pool_size?
    ActiveRecord::Base.connection_pool.disconnect!

    config = ActiveRecord::Base.configurations[Rails.env]
    config['pool'] = db_pool_size if config['pool'].to_i < db_pool_size
    ActiveRecord::Base.establish_connection(config)
  end
end

#increase_db_pool_size?Boolean



81
82
83
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 81

def increase_db_pool_size?
   ForemanTasks.dynflow.required? && !remote? && !Rails.env.test?
end

#initialize_world(world_class = ::Dynflow::World) ⇒ Object



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

def initialize_world(world_class = ::Dynflow::World)
  world_class.new(world_config)
end

#on_init(&block) ⇒ Object



53
54
55
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 53

def on_init(&block)
  @on_init << block
end

#rake_task_with_executor?Boolean



73
74
75
76
77
78
79
# File 'lib/foreman_tasks/dynflow/configuration.rb', line 73

def rake_task_with_executor?
  return false unless defined?(Rake)

  Rake.application.top_level_tasks.any? do |rake_task|
    rake_tasks_with_executor.include?(rake_task)
  end
end

#run_on_init_hooks(world) ⇒ Object



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

def run_on_init_hooks(world)
  @on_init.each { |init| init.call(world) }
end