feat(worker): scale connection pool with worker threads

This will automatically increase the DB connection pool size if the number of threads needed in a worker is less than the maximum pool size configured.
This commit is contained in:
Adam Cooke
2024-03-18 08:12:42 +00:00
parent 7e2acccd1e
commit ea542a0694
3 changed files with 41 additions and 0 deletions
+17
View File
@@ -22,6 +22,8 @@ module Postal
class << self
attr_writer :current_process_type
# Return the path to the config file
#
# @return [String]
@@ -136,6 +138,21 @@ module Postal
end
end
# Change the connection pool size to the given size.
#
# @param new_size [Integer]
# @return [void]
def change_database_connection_pool_size(new_size)
ActiveRecord::Base.connection_pool.disconnect!
config = ActiveRecord::Base.configurations
.configs_for(env_name: Rails.env)
.first
.configuration_hash
ActiveRecord::Base.establish_connection(config.merge(pool: new_size))
end
end
Config = initialize_config