fix: cap postgres connection pools
This commit is contained in:
@@ -17,6 +17,7 @@ interface RuntimeConfig {
|
||||
port: number;
|
||||
databaseUrl: string;
|
||||
logFile: string;
|
||||
databasePoolMax: number;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
tokenKey: string;
|
||||
@@ -113,6 +114,7 @@ function configFromEnv(): RuntimeConfig {
|
||||
port: Number(process.env.PORT || 4244),
|
||||
databaseUrl,
|
||||
logFile: process.env.LOG_FILE || "",
|
||||
databasePoolMax: Math.max(1, Math.min(8, Number(process.env.DATABASE_POOL_MAX || 2) || 2)),
|
||||
clientId: process.env.BAIDU_NETDISK_CLIENT_ID || process.env.BAIDU_NETDISK_APP_KEY || "",
|
||||
clientSecret: process.env.BAIDU_NETDISK_CLIENT_SECRET || process.env.BAIDU_NETDISK_SECRET_KEY || "",
|
||||
tokenKey: process.env.BAIDU_NETDISK_TOKEN_KEY || "",
|
||||
@@ -124,7 +126,12 @@ function configFromEnv(): RuntimeConfig {
|
||||
}
|
||||
|
||||
const config = configFromEnv();
|
||||
const sql = postgres(config.databaseUrl, { max: 8, idle_timeout: 20, connect_timeout: 10 });
|
||||
const sql = postgres(config.databaseUrl, {
|
||||
max: config.databasePoolMax,
|
||||
idle_timeout: 20,
|
||||
connect_timeout: 10,
|
||||
connection: { application_name: "unidesk-baidu-netdisk" },
|
||||
});
|
||||
const logWriter = config.logFile
|
||||
? createHourlyJsonlWriter({
|
||||
baseLogFile: config.logFile,
|
||||
|
||||
@@ -28,6 +28,7 @@ services:
|
||||
CODE_QUEUE_APPROVAL_POLICY: "${CODE_QUEUE_APPROVAL_POLICY:-never}"
|
||||
CODE_QUEUE_MAX_ATTEMPTS: "${CODE_QUEUE_MAX_ATTEMPTS:-99}"
|
||||
CODE_QUEUE_MAX_ACTIVE_QUEUES: "${CODE_QUEUE_MAX_ACTIVE_QUEUES:-0}"
|
||||
CODE_QUEUE_DATABASE_POOL_MAX: "${CODE_QUEUE_DATABASE_POOL_MAX:-2}"
|
||||
NODE_OPTIONS: "${CODE_QUEUE_NODE_OPTIONS:---max-old-space-size=1024}"
|
||||
CODE_QUEUE_IN_MEMORY_OUTPUT_RECORDS: "${CODE_QUEUE_IN_MEMORY_OUTPUT_RECORDS:-10}"
|
||||
CODE_QUEUE_IN_MEMORY_EVENT_RECORDS: "${CODE_QUEUE_IN_MEMORY_EVENT_RECORDS:-10}"
|
||||
|
||||
@@ -184,9 +184,10 @@ let persistDirty = false;
|
||||
let shutdownRequested = false;
|
||||
let serviceReady = false;
|
||||
const sql: SqlClient = postgres(config.databaseUrl, {
|
||||
max: 4,
|
||||
max: config.databasePoolMax,
|
||||
idle_timeout: 20,
|
||||
connect_timeout: 10,
|
||||
connection: { application_name: "unidesk-code-queue" },
|
||||
});
|
||||
let databaseReady = false;
|
||||
let databaseLastError: string | null = null;
|
||||
@@ -322,6 +323,7 @@ function readConfig(): RuntimeConfig {
|
||||
judgeMaxTokens: Math.max(800, Math.min(4000, envNumber("MINIMAX_JUDGE_MAX_TOKENS", 1800))),
|
||||
turnNoActivityTimeoutMs: Math.max(60_000, Math.min(30 * 60_000, envNumber("CODEX_TURN_NO_ACTIVITY_TIMEOUT_MS", 6 * 60_000))),
|
||||
databaseUrl: envRequiredString("DATABASE_URL"),
|
||||
databasePoolMax: Math.max(1, Math.min(8, envNumber("CODE_QUEUE_DATABASE_POOL_MAX", envNumber("DATABASE_POOL_MAX", 2)))),
|
||||
databaseFlushIntervalMs: Math.max(100, Math.min(10_000, envNumber("CODE_QUEUE_DATABASE_FLUSH_INTERVAL_MS", 1000))),
|
||||
oaEventFlowBaseUrl: envString("OA_EVENT_FLOW_BASE_URL", "http://oa-event-flow:4255").replace(/\/+$/u, ""),
|
||||
notifyClaudeQqEnabled: envBool("CODE_QUEUE_NOTIFY_CLAUDEQQ_ENABLED", false),
|
||||
|
||||
@@ -64,6 +64,7 @@ export interface RuntimeConfig {
|
||||
judgeMaxTokens: number;
|
||||
turnNoActivityTimeoutMs: number;
|
||||
databaseUrl: string;
|
||||
databasePoolMax: number;
|
||||
databaseFlushIntervalMs: number;
|
||||
oaEventFlowBaseUrl: string;
|
||||
notifyClaudeQqEnabled: boolean;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -13,6 +13,7 @@ interface RuntimeConfig {
|
||||
port: number;
|
||||
databaseUrl: string;
|
||||
logFile: string;
|
||||
databasePoolMax: number;
|
||||
}
|
||||
|
||||
interface ProjectRow {
|
||||
@@ -90,11 +91,17 @@ function configFromEnv(): RuntimeConfig {
|
||||
port: Number(process.env.PORT || 4233),
|
||||
databaseUrl,
|
||||
logFile: process.env.LOG_FILE || "",
|
||||
databasePoolMax: Math.max(1, Math.min(8, Number(process.env.DATABASE_POOL_MAX || 1) || 1)),
|
||||
};
|
||||
}
|
||||
|
||||
const config = configFromEnv();
|
||||
const sql = postgres(config.databaseUrl, { max: 8, idle_timeout: 20, connect_timeout: 10 });
|
||||
const sql = postgres(config.databaseUrl, {
|
||||
max: config.databasePoolMax,
|
||||
idle_timeout: 20,
|
||||
connect_timeout: 10,
|
||||
connection: { application_name: "unidesk-project-manager" },
|
||||
});
|
||||
const logWriter = config.logFile
|
||||
? createHourlyJsonlWriter({
|
||||
baseLogFile: config.logFile,
|
||||
|
||||
Reference in New Issue
Block a user