mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-10-04 02:04:22 +00:00
wip
This commit is contained in:
@@ -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,
|
||||
|
||||
+4
-2
@@ -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');
|
||||
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
@@ -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 ?
|
||||
|
||||
+16
-3
@@ -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 = [];
|
||||
@@ -152,7 +152,20 @@ const nudgeCallCounts = async(logger, sids, nudgeOperator, writers) => {
|
||||
logger.debug({
|
||||
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) {
|
||||
await addKey(`debug:incalls:${account_sid}:${callId}`, Date.now());
|
||||
}
|
||||
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 }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user