Skip to content

Commit

Permalink
Reduce QuestDB client idle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
loicsaintroch committed Sep 30, 2024
1 parent cd69d25 commit 6fec835
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion services/libs/questdb/src/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ export const getClientSQL = async (): Promise<pgpromise.IDatabase<unknown>> => {
log.info('Creating QuestDB client (SQL) instance!')

client = pgpromise({
// tslint:disable-next-line:max-line-length
// see https://stackoverflow.com/questions/36120435/verify-database-connection-with-pg-promise-when-starting-an-app
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async error(err: any, e: pgpromise.IEventContext): Promise<void> {
if (e.cn) {
log.fatal(err, { cn: e.cn }, 'QuestDB connection error. Stopping process')
// logs don't have flush:
await new Promise((resolve) => setTimeout(resolve, 100))
process.nextTick(() => process.exit())
}

if (e.query) {
log.error(err, { query: e.query, params: e.params }, 'Error executing a QuestDB query!')
}
},
query(e) {
log.debug({ query: e.query, params: e.params }, 'Executing QuestDB query')
},
Expand All @@ -26,7 +41,7 @@ export const getClientSQL = async (): Promise<pgpromise.IDatabase<unknown>> => {
database: process.env['CROWD_QUESTDB_SQL_DATABASE'],
application_name: process.env.SERVICE || 'unknown-app',
ssl: getEnv() !== 'local' ? true : false,
idleTimeoutMillis: 280000,
idleTimeoutMillis: 120000,
})

return client
Expand Down

0 comments on commit 6fec835

Please sign in to comment.