lib/foreman_tasks/dynflow/configuration.rb in foreman-tasks-0.6.0 vs lib/foreman_tasks/dynflow/configuration.rb in foreman-tasks-0.6.1
- old
+ new
@@ -9,10 +9,13 @@
attr_accessor :dynflow_logger
# the number of threads in the pool handling the execution
attr_accessor :pool_size
+ # the size of db connection pool
+ attr_accessor :db_pool_size
+
# set true if the executor runs externally (by default true in procution, othewise false)
attr_accessor :remote
alias_method :remote?, :remote
# if remote set to true, use this path for socket communication
@@ -32,10 +35,11 @@
def initialize
self.action_logger = Rails.logger
self.dynflow_logger = Rails.logger
self.pool_size = 5
+ self.db_pool_size = pool_size + 5
self.remote = Rails.env.production?
self.remote_socket_path = File.join(Rails.root, "tmp", "sockets", "dynflow_socket")
self.transaction_adapter = ::Dynflow::TransactionAdapters::ActiveRecord.new
self.eager_load_paths = []
self.lazy_initialization = !Rails.env.production?
@@ -82,10 +86,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']
if db_config['adapter'] == 'sqlite3'
db_config['adapter'] = 'sqlite'
database = db_config['database']
unless database == ':memory:'
@@ -105,9 +110,22 @@
end
end
# Sequel adapter based on Rails app database.yml configuration
def initialize_persistence
+ unless remote?
+ 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