Skip to content

Commit

Permalink
Merge pull request #683 from near/feat/lower-max-use
Browse files Browse the repository at this point in the history
feat: logging & connection params
  • Loading branch information
andy-haynes committed Mar 13, 2024
2 parents 51ba1a0 + 9767015 commit 4d1a113
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"bluebird": "^3.7.2",
"bn.js": "5.1.0",
"bs58": "^4.0.1",
"bunyan": "^1.8.15",
"dataloader": "^2.0.0",
"debug": "^4.3.1",
"dynamodb": "1.3.0",
Expand Down
24 changes: 23 additions & 1 deletion src/middleware/indexer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Pool } = require('pg');
const Cache = require('node-cache');
const bunyan = require('bunyan');

const {
BRIDGE_TOKEN_FACTORY_ACCOUNT_ID = 'factory.bridge.near',
Expand All @@ -10,9 +11,30 @@ const {

const replicaConnections = JSON.parse(INDEXER_DB_REPLICAS);
const indexerConnection = replicaConnections[(new Date()).valueOf() % replicaConnections.length];
const pool = new Pool({ connectionString: indexerConnection, maxUses: 1000 });
const pool = new Pool({ connectionString: indexerConnection, maxUses: 100 });


let logger;
try {
logger = bunyan.createLogger({ name: 'indexer-logger' });
} catch {
// not empty
}

pool.on('connect', () => {
try {
logger.info({ msg: 'connected' });
} catch {
// not empty
}
});

pool.on('error', (err) => {
try {
logger.error(err);
} catch {
// not empty
}
console.error('Postgres pool error: ', err);
});

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ buffer@^5.5.0:
base64-js "^1.3.1"
ieee754 "^1.1.13"

bunyan@^1.8.14, bunyan@~1.8.12:
bunyan@^1.8.14, bunyan@^1.8.15, bunyan@~1.8.12:
version "1.8.15"
resolved "https://registry.yarnpkg.com/bunyan/-/bunyan-1.8.15.tgz#8ce34ca908a17d0776576ca1b2f6cbd916e93b46"
integrity sha512-0tECWShh6wUysgucJcBAoYegf3JJoZWibxdqhTm7OHPeT42qdjkZ29QCMcKwbgU1kiH+auSIasNRXMLWXafXig==
Expand Down

0 comments on commit 4d1a113

Please sign in to comment.