From cac8efe04270ef060e79b47da65af44cd721402f Mon Sep 17 00:00:00 2001 From: cheetah Date: Sat, 10 Dec 2022 22:11:21 +0100 Subject: [PATCH] added connector config keys and added new status updates for timeouts --- types/ConnectorRegistry.js | 5 ++++- types/MessageManager.js | 15 ++++++++++++--- types/connectors/Connector.js | 1 + types/connectors/eMessagePuppeteerConnector.js | 3 +++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/types/ConnectorRegistry.js b/types/ConnectorRegistry.js index 152206f..63209e2 100644 --- a/types/ConnectorRegistry.js +++ b/types/ConnectorRegistry.js @@ -37,7 +37,10 @@ class ConnectorRegistry { this.events.emit(`msg:status:${ msg.id }:delivered`, msg, uuid) this.reportState(msg, uuid, 'delivered') } - + getConfigKey(connectorName) { + if (!this.Connectors[ connectorName ]) throw "not registred" + return this.Connectors[ connectorName ].configKey + } //W.I.P async receive(data, connector) { diff --git a/types/MessageManager.js b/types/MessageManager.js index 2b26eb6..a44b5f5 100644 --- a/types/MessageManager.js +++ b/types/MessageManager.js @@ -36,6 +36,7 @@ class MessageManager { recvAck: false, // aka "delivered" readAck: false, // "read" response: false, // "resp" + failed: false, // failed deliveryLog: {}, } : { duplexCapable: false, @@ -106,15 +107,22 @@ class MessageManager { let deliveryChain = msg.routingParams.connectors.map((connectorDeliveryTry) => { const connectorName = connectorDeliveryTry[0], connectorArgs = connectorDeliveryTry.slice(1), - connectorConfig = config.connectors[connectorName] + connectorConfig = config.connectors[ ConnectorRegistry.getConfigKey( connectorName ) ] //const UUID = md5(JSON.stringify(connectorDeliveryTry)) + const UUID = connectorName+':'+md5(JSON.stringify([connectorName,...connectorArgs])) + const chainPromise = (res) => { ConnectorRegistry.events.removeAllListeners(`msg:status:${ msgId }:failed`) + const connectorTimeout = !!connectorConfig && !!connectorConfig.duplexTimeout ? connectorConfig.duplexTimeout*1e3 : 30e3 + console.log("connector", connectorName, "duplex Timeout is", connectorTimeout) setTimeout(() => { + console.log(`${ msgId } timed out ${ connectorName }:${ connectorArgs.join(',') }, continuing...`) + ConnectorRegistry.reportState({ id: msgId }, UUID, 'timeout') res([false, 'timeout']) - }, !!connectorConfig && !!connectorConfig.duplexTimeout ? connectorConfig.duplexTimeout*1e3 : 30e3) + }, connectorTimeout) ConnectorRegistry.events.once(`msg:status:${ msgId }:failed`, () => { console.log(`${ msgId } failed via ${ connectorName }:${ connectorArgs.join(',') }, continuing...`) + ConnectorRegistry.reportState({ id: msgId }, UUID, 'failed') res([false, 'failed']) }) console.log(`Trying to deliver msg#${ msg.id } with ${ connectorName }:${ connectorArgs.join(',') }`) @@ -147,6 +155,7 @@ class MessageManager { .catch(($) => { this._clearEventHandlers4MsgID(msgId) console.log('DELIVERY WAS A TOTAL FAILURE', $) + const dLog = this.messages[ msgId ]._routerData.failed = true }) return true } @@ -159,7 +168,7 @@ class MessageManager { let deliveryChain = msg.routingParams.connectors.map((connectorDeliveryTry) => { const connectorName = connectorDeliveryTry[0], connectorArgs = connectorDeliveryTry.slice(1), - connectorConfig = config.connectors[connectorName] + connectorConfig = config.connectors[ ConnectorRegistry.getConfigKey( connectorName ) ] const chainPromise = (res, rej) => { this._clearEventHandlers4MsgID(msgId) setTimeout(() => { diff --git a/types/connectors/Connector.js b/types/connectors/Connector.js index fc13005..1223aa9 100644 --- a/types/connectors/Connector.js +++ b/types/connectors/Connector.js @@ -4,6 +4,7 @@ class Connector { this.name = "_base" this.duplexCapable = false this.supportBOSkrypt = false + this.configKey = this.name } Hook (connectorRegistry) { this.connectorRegistry = connectorRegistry diff --git a/types/connectors/eMessagePuppeteerConnector.js b/types/connectors/eMessagePuppeteerConnector.js index a487fc7..75db5cf 100644 --- a/types/connectors/eMessagePuppeteerConnector.js +++ b/types/connectors/eMessagePuppeteerConnector.js @@ -13,6 +13,7 @@ class eMessagePuppeteerConnectorBase extends Connector { this.defaultServiceName = "" this.duplexCapable = true this.supportBOSkrypt = true + this.configKey = "emPuppettering" } async transmitMessage(msg, params) { const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) @@ -128,6 +129,7 @@ class eMessagePuppeteerConnectorCityruf extends eMessagePuppeteerConnectorBase { this.defaultServiceName = "1" this.duplexCapable = true this.supportBOSkrypt = true + this.configKey = "emPuppettering" } } class eMessagePuppeteerConnectorTwoWays extends eMessagePuppeteerConnectorBase { @@ -137,6 +139,7 @@ class eMessagePuppeteerConnectorTwoWays extends eMessagePuppeteerConnectorBase { this.defaultServiceName = "7" this.duplexCapable = true this.supportBOSkrypt = true + this.configKey = "emPuppettering" } }