-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UNTRACKED/k1ch/ fix knex config, release idle db connection and minor…
… JWKS API bug (#124) * bug-fix: untracked/k1ch/ fix knex config, release idle db connection and minor JWKS API bug * chore: bump version to v2.2.1 * chore: untracked/k1ch/introduce new knex envs * chore: add additional comment to explain idleTimeoutMillis: 0
- Loading branch information
Showing
11 changed files
with
71 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
PGURI=postgres://postgres:tehsecure@usher-db:5432/postgres?sslmode=disable | ||
# Needed by knex for storing migrations table | ||
PGSCHEMA=usher | ||
KNEX_POOL_MIN=0 | ||
KNEX_POOL_MAX=100 | ||
KNEX_POOL_PROPAGATE_CREATE_ERROR=false | ||
KNEX_POOL_CREATE_RETRY_INTERVAL_MILLIS=500 | ||
KNEX_POOL_CREATE_TIMEOUT_MILLIS=5000 | ||
KNEX_POOL_ACQUIRE_TIMEOUT_MILLIS=5000 | ||
KNEX_POOL_REAP_INTERVAL_MILLIS=1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
const knex = require('knex'); | ||
const knexDbConfig = require('../knexfile'); | ||
const knex = require('knex') | ||
const knexDbConfig = require('../knexfile') | ||
|
||
/** | ||
* Usher DB connection instance. | ||
* @name usherDb | ||
* @type {import('knex')} | ||
* @desc This instance provides a connection to the Usher database using Knex.js | ||
* @example // To import usherDb instance | ||
* const { usherDb } = require('./knex'); | ||
* const { usherDb } = require('./knex') | ||
* @example // To perform a database query | ||
* const persona = await usherDb('personas').where('key', personaKey).first(); | ||
* const persona = await usherDb('personas').where('key', personaKey).first() | ||
*/ | ||
const usherDb = knex(knexDbConfig); | ||
let usherDb | ||
try { | ||
usherDb = knex(knexDbConfig) | ||
if (usherDb?.client?.pool) { | ||
const pool = usherDb.client.pool | ||
// Set idle timeout to 0 to release connections immediately. This can't be configured through Knex. | ||
pool.idleTimeoutMillis = 0 | ||
|
||
// Check the pool for idle connections on 'release' event | ||
pool.on('release', () => { | ||
process.nextTick(() => { | ||
pool.check() // Ensures the pool checks for idle connections immediately | ||
}) | ||
}) | ||
} | ||
} catch (err) { | ||
console.error('Failed to create knex instance: ', JSON.stringify(err)) | ||
} | ||
|
||
module.exports = { usherDb } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters