Expose config values for database connection pool

This commit is contained in:
syeopite 2021-09-25 01:56:44 -07:00
parent 82e6f6e095
commit d0480f5381
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
2 changed files with 41 additions and 0 deletions

View file

@ -15,6 +15,29 @@ db:
port: 5432 port: 5432
dbname: invidious dbname: invidious
##
## Granular pooling behavior controls
## The following is entirely optional.
##
## Initial amount of connections in the pool
#initial_pool_size:
## Maximum amount of connections in the pool. 0 is unlimited.
#max_pool_size: 0
## Amount of connections when idle
#max_idle_pool_size: 1
## Amount of seconds to wait if the connection pool is full, and a connection is unavailable.
#checkout_timeout: 5
## Amount of retries when a connection is either lost or can't be established.
#retry_attempts: 1
## Amount of seconds between each retry
#retry_delay: 1
## ##
## Database configuration using a single URI. This is an ## Database configuration using a single URI. This is an
## alternative to the 'db' parameter above. If both forms ## alternative to the 'db' parameter above. If both forms

View file

@ -188,6 +188,16 @@ class Config
host: db.host, host: db.host,
port: db.port, port: db.port,
path: db.dbname, path: db.dbname,
# Pooling config
query: URI::Params.build do |pool_controls|
pool_controls.add "initial_pool_size", db.initial_pool_size.to_s
pool_controls.add "max_pool_size", db.max_pool_size.to_s
pool_controls.add "max_idle_pool_size", db.max_idle_pool_size.to_s
pool_controls.add "checkout_timeout", db.checkout_timeout.to_s
pool_controls.add "retry_attempts", db.retry_attempts.to_s
pool_controls.add "retry_delay", db.retry_delay.to_s
end
) )
else else
puts "Config : Either database_url or db.* is required" puts "Config : Either database_url or db.* is required"
@ -207,6 +217,14 @@ struct DBConfig
property host : String property host : String
property port : Int32 property port : Int32
property dbname : String property dbname : String
# https://crystal-lang.org/reference/database/connection_pool.html#configuration
property initial_pool_size : Int32 = 1
property max_pool_size : Int32 = 0
property max_idle_pool_size : Int32 = 1
property checkout_timeout : Int32 = 5
property retry_attempts : Int32 = 1
property retry_delay : Int32 = 1
end end
def login_req(f_req) def login_req(f_req)