added connector config keys and added new status updates for timeouts

master
cheetah 2 years ago
parent f69aebe935
commit cac8efe042

@ -37,7 +37,10 @@ class ConnectorRegistry {
this.events.emit(`msg:status:${ msg.id }:delivered`, msg, uuid) this.events.emit(`msg:status:${ msg.id }:delivered`, msg, uuid)
this.reportState(msg, uuid, 'delivered') this.reportState(msg, uuid, 'delivered')
} }
getConfigKey(connectorName) {
if (!this.Connectors[ connectorName ]) throw "not registred"
return this.Connectors[ connectorName ].configKey
}
//W.I.P //W.I.P
async receive(data, connector) { async receive(data, connector) {

@ -36,6 +36,7 @@ class MessageManager {
recvAck: false, // aka "delivered" recvAck: false, // aka "delivered"
readAck: false, // "read" readAck: false, // "read"
response: false, // "resp" response: false, // "resp"
failed: false, // failed
deliveryLog: {}, deliveryLog: {},
} : { } : {
duplexCapable: false, duplexCapable: false,
@ -106,15 +107,22 @@ class MessageManager {
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),
connectorConfig = config.connectors[connectorName] connectorConfig = config.connectors[ ConnectorRegistry.getConfigKey( connectorName ) ]
//const UUID = md5(JSON.stringify(connectorDeliveryTry)) //const UUID = md5(JSON.stringify(connectorDeliveryTry))
const UUID = connectorName+':'+md5(JSON.stringify([connectorName,...connectorArgs]))
const chainPromise = (res) => { const chainPromise = (res) => {
ConnectorRegistry.events.removeAllListeners(`msg:status:${ msgId }:failed`) 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(() => { setTimeout(() => {
console.log(`${ msgId } timed out ${ connectorName }:${ connectorArgs.join(',') }, continuing...`)
ConnectorRegistry.reportState({ id: msgId }, UUID, 'timeout')
res([false, 'timeout']) res([false, 'timeout'])
}, !!connectorConfig && !!connectorConfig.duplexTimeout ? connectorConfig.duplexTimeout*1e3 : 30e3) }, 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')
res([false, 'failed']) res([false, 'failed'])
}) })
console.log(`Trying to deliver msg#${ msg.id } with ${ connectorName }:${ connectorArgs.join(',') }`) console.log(`Trying to deliver msg#${ msg.id } with ${ connectorName }:${ connectorArgs.join(',') }`)
@ -147,6 +155,7 @@ class MessageManager {
.catch(($) => { .catch(($) => {
this._clearEventHandlers4MsgID(msgId) this._clearEventHandlers4MsgID(msgId)
console.log('DELIVERY WAS A TOTAL FAILURE', $) console.log('DELIVERY WAS A TOTAL FAILURE', $)
const dLog = this.messages[ msgId ]._routerData.failed = true
}) })
return true return true
} }
@ -159,7 +168,7 @@ class MessageManager {
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),
connectorConfig = config.connectors[connectorName] connectorConfig = config.connectors[ ConnectorRegistry.getConfigKey( connectorName ) ]
const chainPromise = (res, rej) => { const chainPromise = (res, rej) => {
this._clearEventHandlers4MsgID(msgId) this._clearEventHandlers4MsgID(msgId)
setTimeout(() => { setTimeout(() => {

@ -4,6 +4,7 @@ class Connector {
this.name = "_base" this.name = "_base"
this.duplexCapable = false this.duplexCapable = false
this.supportBOSkrypt = false this.supportBOSkrypt = false
this.configKey = this.name
} }
Hook (connectorRegistry) { Hook (connectorRegistry) {
this.connectorRegistry = connectorRegistry this.connectorRegistry = connectorRegistry

@ -13,6 +13,7 @@ class eMessagePuppeteerConnectorBase extends Connector {
this.defaultServiceName = "" this.defaultServiceName = ""
this.duplexCapable = true this.duplexCapable = true
this.supportBOSkrypt = true this.supportBOSkrypt = true
this.configKey = "emPuppettering"
} }
async transmitMessage(msg, params) { async transmitMessage(msg, params) {
const UUID = this.name+':'+md5(JSON.stringify([this.name,...params])) const UUID = this.name+':'+md5(JSON.stringify([this.name,...params]))
@ -128,6 +129,7 @@ class eMessagePuppeteerConnectorCityruf extends eMessagePuppeteerConnectorBase {
this.defaultServiceName = "1" this.defaultServiceName = "1"
this.duplexCapable = true this.duplexCapable = true
this.supportBOSkrypt = true this.supportBOSkrypt = true
this.configKey = "emPuppettering"
} }
} }
class eMessagePuppeteerConnectorTwoWays extends eMessagePuppeteerConnectorBase { class eMessagePuppeteerConnectorTwoWays extends eMessagePuppeteerConnectorBase {
@ -137,6 +139,7 @@ class eMessagePuppeteerConnectorTwoWays extends eMessagePuppeteerConnectorBase {
this.defaultServiceName = "7" this.defaultServiceName = "7"
this.duplexCapable = true this.duplexCapable = true
this.supportBOSkrypt = true this.supportBOSkrypt = true
this.configKey = "emPuppettering"
} }
} }

Loading…
Cancel
Save