class Dynflow::Rails::Configuration
Attributes
the size of db connection pool, if not set, it's calculated from the amount of workers in the pool
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.
the number of threads in the pool handling the execution
what rake tasks should run their own executor, not depending on the external one
set true if the executor runs externally (by default true in procution, othewise false)
set true if the executor runs externally (by default true in procution, othewise false)
what transaction adapater should be used, by default, it uses the ActiveRecord based adapter, expecting ActiveRecord is used as ORM in the application
Public Class Methods
# File lib/dynflow/rails/configuration.rb, line 34 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 = [] end
Public Instance Methods
# File lib/dynflow/rails/configuration.rb, line 89 def calculate_db_pool_size(world) self.db_pool_size || world.config.queues.values.inject(5) do |pool_size, pool_options| pool_size += pool_options[:pool_size] end end
To avoid pottential timeouts on db connection pool, make sure we have the pool bigger than the thread pool
# File lib/dynflow/rails/configuration.rb, line 97 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! 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
# File lib/dynflow/rails/configuration.rb, line 85 def increase_db_pool_size? !::Rails.env.test? && !remote? end
# File lib/dynflow/rails/configuration.rb, line 65 def initialize_world(world_class = ::Dynflow::World) world_class.new(world_config) end
# File lib/dynflow/rails/configuration.rb, line 57 def on_init(&block) @on_init << block end
expose the queues definition to Rails developers
# File lib/dynflow/rails/configuration.rb, line 130 def queues world_config.queues end
# File lib/dynflow/rails/configuration.rb, line 77 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
# File lib/dynflow/rails/configuration.rb, line 61 def run_on_init_hooks(world) @on_init.each { |init| init.call(world) } end
generates the options hash consumable by the Dynflow's world
# File lib/dynflow/rails/configuration.rb, line 113 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 = 5 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 end end
Protected Instance Methods
# File lib/dynflow/rails/configuration.rb, line 136 def default_sequel_adapter_options(world) db_config = ::ActiveRecord::Base.configurations[::Rails.env].dup db_config['adapter'] = db_config['adapter'].gsub(/_?makara_?/, '') db_config['adapter'] = 'postgres' if db_config['adapter'] == 'postgresql' db_config['max_connections'] = calculate_db_pool_size(world) if increase_db_pool_size? if db_config['adapter'] == 'sqlite3' db_config['adapter'] = 'sqlite' database = db_config['database'] unless database == ':memory:' # We need to create separate database for sqlite # to avoid lock conflicts on the database db_config['database'] = "#{File.dirname(database)}/dynflow-#{File.basename(database)}" end end db_config end
# File lib/dynflow/rails/configuration.rb, line 164 def initialize_connector(world) ::Dynflow::Connectors::Database.new(world) end
# File lib/dynflow/rails/configuration.rb, line 154 def initialize_executor(world) if remote? false else ::Dynflow::Executors::Parallel.new(world, world.config.executor_heartbeat_interval, world.config.queues) end end
Sequel adapter based on Rails app database.yml configuration
# File lib/dynflow/rails/configuration.rb, line 173 def initialize_persistence(world) persistence_class.new(default_sequel_adapter_options(world)) end
# File lib/dynflow/rails/configuration.rb, line 168 def persistence_class ::Dynflow::PersistenceAdapters::Sequel end