fix: cap postgres connection pools
This commit is contained in:
@@ -12,6 +12,7 @@ interface RuntimeConfig {
|
||||
port: number;
|
||||
databaseUrl: string;
|
||||
logFile: string;
|
||||
databasePoolMax: number;
|
||||
pipelineBridgeBaseUrl: string;
|
||||
pipelineBridgeIntervalMs: number;
|
||||
pipelineBridgeRunLimit: number;
|
||||
@@ -179,6 +180,7 @@ function configFromEnv(): RuntimeConfig {
|
||||
port: envNumber("PORT", 4255),
|
||||
databaseUrl: envRequiredString("DATABASE_URL"),
|
||||
logFile: envString("LOG_FILE", "/var/log/unidesk/oa-event-flow.jsonl"),
|
||||
databasePoolMax: Math.max(1, Math.min(8, envNumber("DATABASE_POOL_MAX", 2))),
|
||||
pipelineBridgeBaseUrl: envString("PIPELINE_OA_BRIDGE_BASE_URL", "").replace(/\/+$/u, ""),
|
||||
pipelineBridgeIntervalMs: envNumber("PIPELINE_OA_BRIDGE_INTERVAL_MS", 15_000),
|
||||
pipelineBridgeRunLimit: envNumber("PIPELINE_OA_BRIDGE_RUN_LIMIT", 50),
|
||||
@@ -186,7 +188,12 @@ function configFromEnv(): RuntimeConfig {
|
||||
}
|
||||
|
||||
const config = configFromEnv();
|
||||
const sql: SqlClient = postgres(config.databaseUrl, { max: 8, idle_timeout: 20, connect_timeout: 10 });
|
||||
const sql: SqlClient = postgres(config.databaseUrl, {
|
||||
max: config.databasePoolMax,
|
||||
idle_timeout: 20,
|
||||
connect_timeout: 10,
|
||||
connection: { application_name: "unidesk-oa-event-flow" },
|
||||
});
|
||||
const pipelineBridgeState: PipelineBridgeState = {
|
||||
enabled: config.pipelineBridgeBaseUrl.length > 0,
|
||||
mode: "snapshot",
|
||||
|
||||
Reference in New Issue
Block a user