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,
|
||||
|
||||
Reference in New Issue
Block a user