forked from wangziqi/gongxue-base
feat: add docker capacity benchmark mode
This commit is contained in:
@@ -9,10 +9,16 @@ export interface DbPoolOptions {
|
||||
idleTimeoutMillis?: number;
|
||||
}
|
||||
|
||||
function envPoolMax() {
|
||||
const value = Number(process.env.DB_POOL_MAX || 10);
|
||||
if (!Number.isFinite(value) || value <= 0) return 10;
|
||||
return Math.trunc(value);
|
||||
}
|
||||
|
||||
export function createPool(options: DbPoolOptions = {}) {
|
||||
return new Pool({
|
||||
connectionString: options.connectionString || process.env.DATABASE_URL || DEFAULT_DATABASE_URL,
|
||||
max: options.max || 10,
|
||||
max: options.max || envPoolMax(),
|
||||
idleTimeoutMillis: options.idleTimeoutMillis || 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user