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.
      36 37 38 39 40 41 42 43 44 45 46 47  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 36 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
      14 15 16  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 14 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.
      34 35 36  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 34 def disable_active_record_actions @disable_active_record_actions end  | 
  
#eager_load_paths ⇒ Object
Returns the value of attribute eager_load_paths.
      24 25 26  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 24 def eager_load_paths @eager_load_paths end  | 
  
#lazy_initialization ⇒ Object
Returns the value of attribute lazy_initialization.
      26 27 28  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 26 def lazy_initialization @lazy_initialization end  | 
  
#pool_size ⇒ Object
the number of threads in the pool handling the execution
      10 11 12  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 10 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
      29 30 31  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 29 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)
      17 18 19  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 17 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
      22 23 24  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 22 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
      51 52 53  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 51 def action_logger ::Rails.logger end  | 
  
#calculate_db_pool_size(world) ⇒ Object
      107 108 109 110 111 112 113 114 115 116 117 118  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 107 def calculate_db_pool_size(world) return self.db_pool_size if self.db_pool_size base_value = 5 if defined?(::Sidekiq) Sidekiq.configure_server { |c| c[: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
      57 58 59  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 57 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
      122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 122 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
      99 100 101  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 99 def increase_db_pool_size? !::Rails.env.test? && (!remote? || sidekiq_worker?) end  | 
  
#initialize_world(world_class = ::Dynflow::World) ⇒ Object
      79 80 81  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 79 def initialize_world(world_class = ::Dynflow::World) world_class.new(world_config) end  | 
  
#on_init(executor = true, &block) ⇒ Object
      61 62 63 64  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 61 def on_init(executor = true, &block) destination = executor ? @on_executor_init : @on_init destination << block end  | 
  
#post_executor_init(&block) ⇒ Object
      71 72 73  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 71 def post_executor_init(&block) @post_executor_init << block end  | 
  
#queues ⇒ Object
expose the queues definition to Rails developers
      163 164 165  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 163 def queues world_config.queues end  | 
  
#rake_task_with_executor? ⇒ Boolean
      91 92 93 94 95 96 97  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 91 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
      66 67 68 69  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 66 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
      75 76 77  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 75 def run_post_executor_init_hooks(world) @post_executor_init.each { |init| init.call(world) } end  | 
  
#sidekiq_worker? ⇒ Boolean
      103 104 105  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 103 def sidekiq_worker? defined?(::Sidekiq) && ::Sidekiq.configure_server { |c| c[:queues].any? } end  | 
  
#world_config ⇒ Object
generates the options hash consumable by the Dynflow’s world
      143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160  | 
    
      # File 'lib/dynflow/rails/configuration.rb', line 143 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.configure_server { |c| c[:queues].include?("dynflow_orchestrator") } config.delayed_executor = nil end end end  |