Compare commits

...
Author SHA1 Message Date
Dave Horton 5438f4e147 wip 2025-01-10 19:21:14 -05:00
Dave Horton dd2a4fead5 wip 2025-01-10 19:17:41 -05:00
Dave Horton e706d60c10 wip 2025-01-10 19:15:08 -05:00
Dave Horton 6e892cb48f wip 2025-01-10 19:06:29 -05:00
Dave Horton 53a205db7d wip 2025-01-10 19:05:47 -05:00
4 changed files with 32 additions and 11 deletions
+2
View File
@@ -68,6 +68,7 @@ const {
const {
client: redisClient,
addKey,
deleteKey,
retrieveKey,
createSet,
retrieveSet,
@@ -111,6 +112,7 @@ srf.locals = {...srf.locals,
},
realtimeDbHelpers: {
addKey,
deleteKey,
retrieveKey,
createSet,
incrKey,
+5 -3
View File
@@ -454,13 +454,15 @@ class CallSession extends Emitter {
if (process.env.JAMBONES_HOSTING || trackingOn) {
const {writeCallCount, writeCallCountSP, writeCallCountApp} = this.req.srf.locals;
if (!this.req.locals.callCountNudged) {
const {callId} = this.req.locals;
this.req.locals.callCountNudged = true;
this.logger.debug('decrementing call count at end of call');
this.logger.info('decrementing call count at end of call due to normal termination');
await nudgeCallCounts(this.logger, {
service_provider_sid: this.service_provider_sid,
account_sid: this.account_sid,
application_sid: this.application_sid
}, this.decrKey, {writeCallCountSP, writeCallCount, writeCallCountApp})
application_sid: this.application_sid,
callId
}, this.decrKey, {writeCallCountSP, writeCallCount, writeCallCountApp}, -1)
.catch((err) => this.logger.error(err, 'Error decrementing call counts'));
}
}
+7 -4
View File
@@ -248,6 +248,7 @@ module.exports = function(srf, logger) {
};
const checkLimits = async(req, res, next) => {
const {callId} = req.locals;
const trackingOn = process.env.JAMBONES_TRACK_ACCOUNT_CALLS ||
process.env.JAMBONES_TRACK_SP_CALLS ||
process.env.JAMBONES_TRACK_APP_CALLS;
@@ -267,8 +268,9 @@ module.exports = function(srf, logger) {
nudgeCallCounts(logger, {
service_provider_sid,
account_sid,
application_sid
}, decrKey, {writeCallCountSP, writeCallCount, writeCallCountApp})
application_sid,
callId
}, decrKey, {writeCallCountSP, writeCallCount, writeCallCountApp}, -1)
.catch((err) => logger.error(err, 'Error decrementing call counts'));
}
});
@@ -278,8 +280,9 @@ module.exports = function(srf, logger) {
const {callsSP, calls} = await nudgeCallCounts(logger, {
service_provider_sid,
account_sid,
application_sid
}, incrKey, {writeCallCountSP, writeCallCount, writeCallCountApp});
application_sid,
callId
}, incrKey, {writeCallCountSP, writeCallCount, writeCallCountApp}, 1);
/* compare to account's limit, though avoid db hit when call count is low */
const minLimit = process.env.MIN_CALL_LIMIT ?
+18 -4
View File
@@ -117,8 +117,8 @@ const createHealthCheckApp = (port, logger) => {
});
};
const nudgeCallCounts = async(logger, sids, nudgeOperator, writers) => {
const { service_provider_sid, account_sid, application_sid } = sids;
const nudgeCallCounts = async(logger, sids, nudgeOperator, writers, direction) => {
const { service_provider_sid, account_sid, callId, application_sid } = sids;
const { writeCallCount, writeCallCountSP, writeCallCountApp } = writers;
const nudges = [];
const writes = [];
@@ -149,10 +149,24 @@ const nudgeCallCounts = async(logger, sids, nudgeOperator, writers) => {
try {
const [callsSP, calls, callsApp] = await Promise.all(nudges);
logger.debug({
logger.info({
calls, callsSP, callsApp,
service_provider_sid, account_sid, application_sid
}, 'call counts after adjustment');
}, `call counts after ${direction > 0 ? 'increment' : 'decrement'}`);
//if (process.env.JAMBONES_DEBUG_CALL_COUNTS) {
const {srf} = require('..');
const {addKey, deleteKey} = srf.locals.realtimeDbHelpers;
if (direction > 0) {
// save for 3 days
await addKey(`debug:incalls:${account_sid}:${callId}`, new Date().toISOString(), 259200);
}
else {
await deleteKey(`debug:incalls:${account_sid}:${callId}`);
}
//}
if (process.env.JAMBONES_TRACK_SP_CALLS) {
writes.push(writeCallCountSP({ service_provider_sid, calls_in_progress: callsSP }));
}