more queue fixes

This commit is contained in:
Dave Horton
2020-05-07 13:28:41 -04:00
parent a0508a2494
commit 1d9658905f
7 changed files with 72 additions and 25 deletions

View File

@@ -31,6 +31,7 @@ class TaskEnqueue extends Task {
notifyUrl: this.data._.notifyUrl
};
this.waitStartTime = this.data._.waitStartTime;
this.connectTime = this.data._.connectTime;
}
}
@@ -47,9 +48,12 @@ class TaskEnqueue extends Task {
await this._doWait(cs, dlg, ep);
}
else {
// update dialog's answer time to when it was answered on the previous server, not now
dlg.connectTime = this.connectTime;
await this._doBridge(cs, dlg, ep);
}
if (!this.callMoved) await this.performAction();
await this.awaitTaskDone();
this.logger.debug(`TaskEnqueue:exec - task done queue ${this.queueName}`);
} catch (err) {
@@ -61,6 +65,7 @@ class TaskEnqueue extends Task {
super.kill(cs);
this.logger.info(`TaskEnqueue:kill ${this.queueName}`);
this.emitter.emit('kill');
this.notifyTaskDone();
}
async _addToQueue(cs, dlg) {
@@ -153,7 +158,8 @@ class TaskEnqueue extends Task {
const success = await this.transferCallToFeatureServer(cs, this.bridgeDetails.dequeueSipAddress, {
waitStartTime: this.waitStartTime,
epUuid: this.bridgeDetails.epUuid,
notifyUrl: this.bridgeDetails.notifyUrl
notifyUrl: this.bridgeDetails.notifyUrl,
connectTime: dlg.connectTime.valueOf()
});
/**
@@ -169,30 +175,29 @@ class TaskEnqueue extends Task {
return;
}
this.state = QueueResults.Error;
this.notifyTaskDone();
return;
}
this.logger.info(`TaskEnqueue:_doBridge: queue ${this.queueName} is hosted locally`);
await this._bridgeLocal(cs, dlg, ep);
this.notifyTaskDone();
}
_bridgeLocal(cs, dlg, ep) {
assert(this.bridgeDetails.epUuid && this.bridgeDetails.notifyUrl);
assert(this.bridgeDetails.notifyUrl);
return new Promise(async(resolve, reject) => {
try {
this.other = {epUuid: this.bridgeDetails.epUuid};
// bridge to the dequeuing endpoint
this.logger.debug(`TaskEnqueue:_doBridge: attempting to bridge call to ${this.other.epUuid}`);
await ep.bridge(this.other.epUuid);
this.state = QueueResults.Bridged;
this.logger.info(`TaskEnqueue:_doBridge: successfully bridged to ${this.other.epUuid}`);
// notify partner we are on - give him our possibly new url
// notify partner we are ready to be bridged - giving him our possibly new url and endpoint
const notifyUrl = getUrl(cs);
const url = this.bridgeDetails.notifyUrl;
this.logger.debug('TaskEnqueue:_doBridge: ready to be bridged');
bent('POST', 202)(url, {
event: 'bridged',
notifyUrl: getUrl(cs)
event: 'ready',
epUuid: ep.uuid,
notifyUrl
}).catch((err) => {
this.logger.info({err, url}, 'TaskEnqueue:_bridgeLocal error sending bridged event');
/**
@@ -220,9 +225,10 @@ class TaskEnqueue extends Task {
});
resolve();
});
} catch (err) {
this.state = QueueResults.Error;
this.logger.error(err, `Failed to bridge to ep ${this.other.epUuid}`);
this.logger.error(err, 'TaskEnqueue:_bridgeLocal error');
reject(err);
}
});