diff --git a/README.md b/README.md index 270b04e..7942c15 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ You can additionally set: * PACT_BROKER_DATABASE_SSLMODE (optional, possible values: 'disable', 'allow', 'prefer', 'require', 'verify-ca', or 'verify-full' to choose how to treat SSL (only respected if using the postgres database adapter). See https://www.postgresql.org/docs/9.1/libpq-ssl.html for more information.) * PACT_BROKER_SQL_LOG_LEVEL (optional, defaults to debug. The level at which to log SQL statements.) * PACT_BROKER_SQL_LOG_WARN_DURATION (optional, defaults to 5 seconds. Log the SQL for queries that take longer than this number of seconds) + * `PACT_BROKER_DATABASE_MAX_CONNECTIONS` - optional, defaults to 4. The maximum size of the connection pool. + * `PACT_BROKER_DATABASE_POOL_TIMEOUT` - optional, 5 seconds by default. The number of seconds to wait if a connection cannot be acquired before raising an error. ## Notes diff --git a/pact_broker/docker_configuration.rb b/pact_broker/docker_configuration.rb index 3561be6..3e7752e 100644 --- a/pact_broker/docker_configuration.rb +++ b/pact_broker/docker_configuration.rb @@ -39,7 +39,9 @@ def database_configuration encoding: 'utf8', sslmode: env_or_nil(:database_sslmode), sql_log_level: (env_or_nil(:sql_log_level) || 'debug').downcase.to_sym, - log_warn_duration: (env_or_nil(:sql_log_warn_duration) || '5').to_f + log_warn_duration: (env_or_nil(:sql_log_warn_duration) || '5').to_f, + max_connections: env_as_integer(:database_max_connections), + pool_timeout: env_as_integer(:database_pool_timeout) ).compact end @@ -79,6 +81,10 @@ def env_or_nil name env_populated?(name) ? env(name) : nil end + def env_as_integer name, default = nil + env_populated?(name) ? env(name).to_i : default + end + def default property_name @default_configuration.send(property_name) end diff --git a/spec/docker_configuration_spec.rb b/spec/docker_configuration_spec.rb index 22b1c73..7ed00f5 100644 --- a/spec/docker_configuration_spec.rb +++ b/spec/docker_configuration_spec.rb @@ -171,6 +171,17 @@ context "when a port is not supplied" do its("database_configuration.keys") { are_expected.not_to include :port } end + + context "when the max connections and pool is supplied" do + let(:db_env) do + super().merge( + "PACT_BROKER_DATABASE_MAX_CONNECTIONS" => "2", + "PACT_BROKER_DATABASE_POOL_TIMEOUT" => "7", + ) + end + + its(:database_configuration) { is_expected.to include max_connections: 2, pool_timeout: 7 } + end end end