Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
configurable max_connections for api/worker, default to 100 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner authored Feb 2, 2024
1 parent 0426a81 commit 0178885
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions hook-api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub struct Config {

#[envconfig(default = "default")]
pub queue_name: String,

#[envconfig(default = "100")]
pub max_pg_connections: u32,
}

impl Config {
Expand Down
1 change: 1 addition & 0 deletions hook-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async fn main() {
// side, but we don't need more than one queue for now.
&config.queue_name,
&config.database_url,
config.max_pg_connections,
"hook-api",
)
.await
Expand Down
11 changes: 9 additions & 2 deletions hook-common/src/pgqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,19 @@ impl PgQueue {
///
/// * `queue_name`: A name for the queue we are going to initialize.
/// * `url`: A URL pointing to where the PostgreSQL database is hosted.
pub async fn new(queue_name: &str, url: &str, app_name: &'static str) -> PgQueueResult<Self> {
pub async fn new(
queue_name: &str,
url: &str,
max_connections: u32,
app_name: &'static str,
) -> PgQueueResult<Self> {
let name = queue_name.to_owned();
let options = PgConnectOptions::from_str(url)
.map_err(|error| PgQueueError::PoolCreationError { error })?
.application_name(app_name);
let pool = PgPoolOptions::new().connect_lazy_with(options);
let pool = PgPoolOptions::new()
.max_connections(max_connections)
.connect_lazy_with(options);

Ok(Self { name, pool })
}
Expand Down
3 changes: 3 additions & 0 deletions hook-worker/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct Config {
#[envconfig(default = "1024")]
pub max_concurrent_jobs: usize,

#[envconfig(default = "100")]
pub max_pg_connections: u32,

#[envconfig(nested = true)]
pub retry_policy: RetryPolicyConfig,

Expand Down
1 change: 1 addition & 0 deletions hook-worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async fn main() -> Result<(), WorkerError> {
let queue = PgQueue::new(
config.queue_name.as_str(),
&config.database_url,
config.max_pg_connections,
"hook-worker",
)
.await
Expand Down

0 comments on commit 0178885

Please sign in to comment.