Class: Dynflow::Rails::Configuration
- Inherits:
-
Object
- Object
- Dynflow::Rails::Configuration
- Defined in:
- lib/dynflow/rails/configuration.rb
Instance Attribute Summary collapse
-
#db_pool_size ⇒ Object
the size of db connection pool, if not set, it’s calculated from the amount of workers in the 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
Action related info such as exceptions raised inside the actions’ methods To be overridden in the Rails application.
- #calculate_db_pool_size(world) ⇒ Object
-
#dynflow_logger ⇒ Object
Dynflow related info about the progress of the execution To be overridden in the Rails application.
-
#increase_db_pool_size(world = nil) ⇒ 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(executor = true, &block) ⇒ Object
- #post_executor_init(&block) ⇒ Object
-
#queues ⇒ Object
expose the queues definition to Rails developers.
- #rake_task_with_executor? ⇒ Boolean
- #run_on_init_hooks(executor, world) ⇒ Object
- #run_post_executor_init_hooks(world) ⇒ Object
- #sidekiq_worker? ⇒ Boolean
-
#world_config ⇒ Object
generates the options hash consumable by the Dynflow’s world.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dynflow/rails/configuration.rb', line 35 def initialize self.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 = [] @on_executor_init = [] @post_executor_init = [] end |
Instance Attribute Details
#db_pool_size ⇒ Object
the size of db connection pool, if not set, it’s calculated from the amount of workers in the pool
13 14 15 |
# File 'lib/dynflow/rails/configuration.rb', line 13 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.
33 34 35 |
# File 'lib/dynflow/rails/configuration.rb', line 33 def disable_active_record_actions @disable_active_record_actions end |
#eager_load_paths ⇒ Object
Returns the value of attribute eager_load_paths.
23 24 25 |
# File 'lib/dynflow/rails/configuration.rb', line 23 def eager_load_paths @eager_load_paths end |
#lazy_initialization ⇒ Object
Returns the value of attribute lazy_initialization.
25 26 27 |
# File 'lib/dynflow/rails/configuration.rb', line 25 def lazy_initialization @lazy_initialization end |
#pool_size ⇒ Object
the number of threads in the pool handling the execution
9 10 11 |
# File 'lib/dynflow/rails/configuration.rb', line 9 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
28 29 30 |
# File 'lib/dynflow/rails/configuration.rb', line 28 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)
16 17 18 |
# File 'lib/dynflow/rails/configuration.rb', line 16 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
21 22 23 |
# File 'lib/dynflow/rails/configuration.rb', line 21 def transaction_adapter @transaction_adapter end |
Instance Method Details
#action_logger ⇒ Object
Action related info such as exceptions raised inside the actions’ methods To be overridden in the Rails application
50 51 52 |
# File 'lib/dynflow/rails/configuration.rb', line 50 def action_logger ::Rails.logger end |
#calculate_db_pool_size(world) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dynflow/rails/configuration.rb', line 106 def calculate_db_pool_size(world) return self.db_pool_size if self.db_pool_size base_value = 5 if defined?(::Sidekiq) Sidekiq.[:concurrency] + base_value else world.config.queues.values.inject(base_value) do |pool_size, | pool_size += [:pool_size] end end end |
#dynflow_logger ⇒ Object
Dynflow related info about the progress of the execution To be overridden in the Rails application
56 57 58 |
# File 'lib/dynflow/rails/configuration.rb', line 56 def dynflow_logger ::Rails.logger end |
#increase_db_pool_size(world = nil) ⇒ Object
To avoid pottential timeouts on db connection pool, make sure we have the pool bigger than the thread pool
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/dynflow/rails/configuration.rb', line 121 def increase_db_pool_size(world = nil) if world.nil? warn 'Deprecated: using `increase_db_pool_size` outside of Dynflow code is not needed anymore' return end if increase_db_pool_size? db_pool_size = calculate_db_pool_size(world) ::ActiveRecord::Base.connection_pool.disconnect! base_config = ::ActiveRecord::Base.configurations.configs_for(env_name: ::Rails.env)[0] config = if base_config.respond_to?(:configuration_hash) ::Dynflow::Utils::IndifferentHash.new(base_config.configuration_hash.dup) else base_config.config.dup end 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
98 99 100 |
# File 'lib/dynflow/rails/configuration.rb', line 98 def increase_db_pool_size? !::Rails.env.test? && (!remote? || sidekiq_worker?) end |
#initialize_world(world_class = ::Dynflow::World) ⇒ Object
78 79 80 |
# File 'lib/dynflow/rails/configuration.rb', line 78 def initialize_world(world_class = ::Dynflow::World) world_class.new(world_config) end |
#on_init(executor = true, &block) ⇒ Object
60 61 62 63 |
# File 'lib/dynflow/rails/configuration.rb', line 60 def on_init(executor = true, &block) destination = executor ? @on_executor_init : @on_init destination << block end |
#post_executor_init(&block) ⇒ Object
70 71 72 |
# File 'lib/dynflow/rails/configuration.rb', line 70 def post_executor_init(&block) @post_executor_init << block end |
#queues ⇒ Object
expose the queues definition to Rails developers
162 163 164 |
# File 'lib/dynflow/rails/configuration.rb', line 162 def queues world_config.queues end |
#rake_task_with_executor? ⇒ Boolean
90 91 92 93 94 95 96 |
# File 'lib/dynflow/rails/configuration.rb', line 90 def rake_task_with_executor? return false unless defined?(::Rake) && ::Rake.respond_to?(:application) ::Rake.application.top_level_tasks.any? do |rake_task| rake_tasks_with_executor.include?(rake_task) end end |
#run_on_init_hooks(executor, world) ⇒ Object
65 66 67 68 |
# File 'lib/dynflow/rails/configuration.rb', line 65 def run_on_init_hooks(executor, world) source = executor ? @on_executor_init : @on_init source.each { |init| init.call(world) } end |
#run_post_executor_init_hooks(world) ⇒ Object
74 75 76 |
# File 'lib/dynflow/rails/configuration.rb', line 74 def run_post_executor_init_hooks(world) @post_executor_init.each { |init| init.call(world) } end |
#sidekiq_worker? ⇒ Boolean
102 103 104 |
# File 'lib/dynflow/rails/configuration.rb', line 102 def sidekiq_worker? defined?(::Sidekiq) && ::Sidekiq.[:queues].any? end |
#world_config ⇒ Object
generates the options hash consumable by the Dynflow’s world
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/dynflow/rails/configuration.rb', line 142 def world_config @world_config ||= ::Dynflow::Config.new.tap do |config| config.auto_rescue = true config.logger_adapter = ::Dynflow::LoggerAdapters::Delegator.new(action_logger, dynflow_logger) config.pool_size = self.pool_size config.persistence_adapter = ->(world, _) { initialize_persistence(world) } config.transaction_adapter = transaction_adapter config.executor = ->(world, _) { initialize_executor(world) } config.connector = ->(world, _) { initialize_connector(world) } # we can't do any operation until the Rails.application.dynflow.world is set config.auto_execute = false config.auto_validity_check = false if sidekiq_worker? && !Sidekiq.[:queues].include?("dynflow_orchestrator") config.delayed_executor = nil end end end |