Class: ForemanTasks::Dynflow::Configuration
- Inherits:
-
Object
- Object
- ForemanTasks::Dynflow::Configuration
- Defined in:
- lib/foreman_tasks/dynflow/configuration.rb
Instance Attribute Summary collapse
-
#db_pool_size ⇒ Object
the size of db connection pool.
-
#disable_active_record_actions ⇒ Object
if true, the ForemanTasks::Concerns::ActionTriggering will make no effect.
-
#eager_load_paths ⇒ Object
Returns the value of attribute eager_load_paths.
-
#lazy_initialization ⇒ Object
Returns the value of attribute lazy_initialization.
-
#pool_size ⇒ Object
the number of threads in the pool handling the execution.
-
#rake_tasks_with_executor ⇒ Object
what rake tasks should run their own executor, not depending on the external one.
-
#remote ⇒ Object
(also: #remote?)
set true if the executor runs externally (by default true in procution, othewise false).
-
#transaction_adapter ⇒ Object
what transaction adapater should be used, by default, it uses the ActiveRecord based adapter, expecting ActiveRecord is used as ORM in the application.
Instance Method Summary collapse
-
#action_logger ⇒ Object
for logging action related info (such as exceptions raised in side the actions’ methods.
-
#dynflow_logger ⇒ Object
for logging dynflow related info about the progress of the execution etc.
-
#increase_db_pool_size ⇒ Object
To avoid pottential timeouts on db connection pool, make sure we have the pool bigger than the thread pool.
- #increase_db_pool_size? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #initialize_world(world_class = ::Dynflow::World) ⇒ Object
- #on_init(&block) ⇒ Object
- #rake_task_with_executor? ⇒ Boolean
- #run_on_init_hooks(world) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_size ⇒ Object
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_actions ⇒ Object
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_paths ⇒ Object
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_initialization ⇒ Object
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_size ⇒ Object
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_executor ⇒ Object
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 |
#remote ⇒ Object 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_adapter ⇒ Object
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_logger ⇒ Object
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_logger ⇒ Object
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_size ⇒ Object
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 |