lib/foreman_tasks/dynflow/configuration.rb in foreman-tasks-0.6.2 vs lib/foreman_tasks/dynflow/configuration.rb in foreman-tasks-0.6.3

- old
+ new

@@ -72,10 +72,26 @@ Rake.application.top_level_tasks.any? do |rake_task| rake_tasks_with_executor.include?(rake_task) end end + def increase_db_pool_size? + ForemanTasks.dynflow.required? && !remote? && !Rails.env.test? + end + + # To avoid pottential timeouts on db connection pool, make sure + # we have the pool bigger than the thread pool + 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 + protected # generates the options hash consumable by the Dynflow's world def world_options { logger_adapter: ::Dynflow::LoggerAdapters::Delegator.new(action_logger, dynflow_logger), @@ -86,11 +102,11 @@ end def default_sequel_adapter_options db_config = ActiveRecord::Base.configurations[Rails.env].dup db_config['adapter'] = 'postgres' if db_config['adapter'] == 'postgresql' - db_config['max_connections'] = db_config['pool'] if db_config['pool'] + db_config['max_connections'] = db_pool_size if increase_db_pool_size? if db_config['adapter'] == 'sqlite3' db_config['adapter'] = 'sqlite' database = db_config['database'] unless database == ':memory:' @@ -110,22 +126,10 @@ end end # Sequel adapter based on Rails app database.yml configuration def initialize_persistence - if !remote && !Rails.env.test? - increase_db_pool_size - end ForemanTasks::Dynflow::Persistence.new(default_sequel_adapter_options) end - # To avoid pottential timeouts on db connection pool, make sure - # we have the pool bigger than the thread pool - def 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 end