Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nt-be/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nt-be/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ hex = "0.4"
serde_with = { version = "3.16.1", features = ["base64"] }
chrono = "0.4"
futures = "0.3"
log = "0.4"
async-stream = "0.3"
governor = "0.7"
sqlx = { version = "0.8", features = [
Expand Down
22 changes: 21 additions & 1 deletion nt-be/src/app_state.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use axum::http::StatusCode;
use chrono::{DateTime, Utc};
use near_api::{AccountId, NetworkConfig, RPCEndpoint, Signer};
use sqlx::ConnectOptions as _;
use sqlx::PgPool;
use std::str::FromStr as _;
use std::{sync::Arc, time::Duration};
use tokio::sync::broadcast;

Expand Down Expand Up @@ -511,6 +513,24 @@ impl AppState {
.and_then(|v| v.parse::<u64>().ok())
.filter(|v| *v >= 1)
.unwrap_or(10);
// Slow-statement WARN threshold. sqlx defaults to 1s, which is too
// sensitive for this workload — the apalis-board admin pages run heavy
// full-table analytics over `apalis.jobs` (the `/overview` and `/queues`
// aggregates take ~1.5s) and legitimately warn on every load. Raise it
// (default 5s, `DB_SLOW_STATEMENT_THRESHOLD_SECONDS`) so routine
// multi-second analytics don't spam WARN while genuinely pathological
// statements (the seconds-long token/backfill queries) still surface.
let slow_statement_secs = std::env::var("DB_SLOW_STATEMENT_THRESHOLD_SECONDS")
.ok()
.and_then(|v| v.parse::<u64>().ok())
.filter(|v| *v >= 1)
.unwrap_or(5);
let connect_options = sqlx::postgres::PgConnectOptions::from_str(&env_vars.database_url)
.map_err(|e| format!("invalid DATABASE_URL: {e}"))?
.log_slow_statements(
log::LevelFilter::Warn,
Duration::from_secs(slow_statement_secs),
);
tracing::info!(max_connections, "Connecting to database...");
let db_pool = sqlx::postgres::PgPoolOptions::new()
.max_connections(max_connections)
Expand All @@ -519,7 +539,7 @@ impl AppState {
.idle_timeout(Duration::from_secs(600))
.max_lifetime(Duration::from_secs(1800))
.test_before_acquire(true)
.connect(&env_vars.database_url)
.connect_with(connect_options)
.await?;

tracing::info!("Running database migrations...");
Expand Down
Loading