clearing all timeout timers when delivered successful

master
cheetah 2 years ago
parent 53e0bd5c0f
commit d66b265795

@ -104,6 +104,7 @@ class MessageManager {
if (!!msg.locked) throw 'message is locked' if (!!msg.locked) throw 'message is locked'
//console.log(msg.routingParams.connectors) //console.log(msg.routingParams.connectors)
let timeoutList = []
let deliveryChain = msg.routingParams.connectors.map((connectorDeliveryTry) => { let deliveryChain = msg.routingParams.connectors.map((connectorDeliveryTry) => {
const connectorName = connectorDeliveryTry[0], const connectorName = connectorDeliveryTry[0],
connectorArgs = connectorDeliveryTry.slice(1), connectorArgs = connectorDeliveryTry.slice(1),
@ -115,11 +116,13 @@ class MessageManager {
ConnectorRegistry.events.removeAllListeners(`msg:status:${ msgId }:failed`) ConnectorRegistry.events.removeAllListeners(`msg:status:${ msgId }:failed`)
const connectorTimeout = !!connectorConfig && !!connectorConfig.duplexTimeout ? connectorConfig.duplexTimeout*1e3 : 30e3 const connectorTimeout = !!connectorConfig && !!connectorConfig.duplexTimeout ? connectorConfig.duplexTimeout*1e3 : 30e3
console.log("connector", connectorName, "duplex Timeout is", connectorTimeout) console.log("connector", connectorName, "duplex Timeout is", connectorTimeout)
setTimeout(() => { timeoutList.push(
console.log(`${ msgId } timed out ${ connectorName }:${ connectorArgs.join(',') }, continuing...`) setTimeout(() => {
ConnectorRegistry.reportState({ id: msgId }, UUID, 'timeout') console.log(`${ msgId } timed out ${ connectorName }:${ connectorArgs.join(',') }, continuing...`)
res([false, 'timeout']) ConnectorRegistry.reportState({ id: msgId }, UUID, 'timeout')
}, connectorTimeout) res([false, 'timeout'])
}, connectorTimeout)
)
ConnectorRegistry.events.once(`msg:status:${ msgId }:failed`, () => { ConnectorRegistry.events.once(`msg:status:${ msgId }:failed`, () => {
console.log(`${ msgId } failed via ${ connectorName }:${ connectorArgs.join(',') }, continuing...`) console.log(`${ msgId } failed via ${ connectorName }:${ connectorArgs.join(',') }, continuing...`)
ConnectorRegistry.reportState({ id: msgId }, UUID, 'failed') ConnectorRegistry.reportState({ id: msgId }, UUID, 'failed')
@ -134,6 +137,7 @@ class MessageManager {
new Promise(res => { // Delivery Event for this message new Promise(res => { // Delivery Event for this message
ConnectorRegistry.events.once(`msg:status:${ msgId }:delivered`, (_, uuid) => { ConnectorRegistry.events.once(`msg:status:${ msgId }:delivered`, (_, uuid) => {
console.log(`${ msgId } delivered via ${ uuid }`) console.log(`${ msgId } delivered via ${ uuid }`)
for (let x of timeoutList) clearTimeout(x)
return res() return res()
}) })
}), }),
@ -150,7 +154,8 @@ class MessageManager {
.then(($) => { .then(($) => {
this._clearEventHandlers4MsgID(msgId) this._clearEventHandlers4MsgID(msgId)
const dLog = this.messages[ msgId ]._routerData.deliveryLog const dLog = this.messages[ msgId ]._routerData.deliveryLog
console.log('DELIVERY WAS A SUCCESS', Object.keys(dLog).map(x=>`${ x } is ${ dLog[x] }`).join('\n')) for (let x of timeoutList) clearTimeout(x)
//console.log('DELIVERY WAS A SUCCESS', Object.keys(dLog).map(x=>`${ x } is ${ dLog[x] }`).join('\n'))
}) })
.catch(($) => { .catch(($) => {
this._clearEventHandlers4MsgID(msgId) this._clearEventHandlers4MsgID(msgId)

Loading…
Cancel
Save