mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-10-04 02:04:22 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5438f4e147 | ||
|
|
dd2a4fead5 | ||
|
|
e706d60c10 | ||
|
|
6e892cb48f | ||
|
|
53a205db7d |
@@ -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
@@ -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
@@ -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
@@ -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 }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user