limit simring outdials to 10 and eliminate any duplicates

This commit is contained in:
Dave Horton
2020-01-25 12:29:18 -05:00
parent 4a1ea4e091
commit 1da1776d45
2 changed files with 38 additions and 4 deletions

View File

@@ -1,12 +1,45 @@
const Task = require('./task');
const makeTask = require('./make_task');
const {CallStatus, CallDirection, TaskName, TaskPreconditions} = require('../utils/constants');
const {CallStatus, CallDirection, TaskName, TaskPreconditions, MAX_SIMRINGS} = require('../utils/constants');
const assert = require('assert');
const placeCall = require('../utils/place-outdial');
const config = require('config');
const moment = require('moment');
const debug = require('debug')('jambonz:feature-server');
function compareTasks(t1, t2) {
if (t1.type !== t2.type) return false;
switch (t1.type) {
case 'phone':
return t1.number === t1.number;
case 'user':
return t2.name === t1.name;
case 'sip':
return t2.uri === t1.uri;
}
}
/**
* Allow at most 10 targets and eliminate duplicates
*/
function filterAndLimit(logger, tasks) {
assert(Array.isArray(tasks));
const unique = tasks.reduce((acc, t) => {
if (acc.find((el) => compareTasks(el, t))) return acc;
return [...acc, t];
}, []);
if (unique.length !== tasks.length) {
logger.info(`filterAndLimit: removed ${tasks.length - unique.length} duplicate dial targets`);
}
if (unique.length > MAX_SIMRINGS) {
logger.info(`filterAndLimit: max number of targets exceeded: ${unique.length}; first ${MAX_SIMRINGS} will be used`);
unique.length = MAX_SIMRINGS;
}
return unique;
}
class TaskDial extends Task {
constructor(logger, opts) {
super(logger, opts);
@@ -19,7 +52,7 @@ class TaskDial extends Task {
this.method = this.data.method || 'POST';
this.statusCallback = this.data.statusCallback;
this.statusCallbackMethod = this.data.statusCallbackMethod || 'POST';
this.target = this.data.target;
this.target = filterAndLimit(this.logger, this.data.target);
this.timeout = this.data.timeout || 60;
this.timeLimit = this.data.timeLimit;
this.url = this.data.url;
@@ -46,7 +79,7 @@ class TaskDial extends Task {
}
await this._attemptCalls(cs);
await this.awaitTaskDone();
this.performAction(this.method, this.results);
this.performAction(this.method, null, this.results);
} catch (err) {
this.logger.error(`TaskDial:exec terminating with error ${err.message}`);
this.kill();

View File

@@ -50,5 +50,6 @@
"Error": "mod_audio_fork::error",
"BufferOverrun": "mod_audio_fork::buffer_overrun",
"JsonMessage": "mod_audio_fork::json"
}
},
"MAX_SIMRINGS": 10
}