Last active
January 12, 2024 18:17
-
-
Save jonbartels/bc1f9e33031290dfe93fa05283dcd23d to your computer and use it in GitHub Desktop.
Alert receiver channel which does not alert if a message queued
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//can use this to get the message content and check state and send attempts | |
// we have channelId and messageId | |
// pass metadataIds as null -> the connector message returned will then have one or many connector messages. #0 is the source, and source has connectorMessage.getDestinationIdMap(); which we can iterate to turn our connector name into the numeric metadata id | |
var shouldAlert = true; | |
var metaDataIds = null; | |
var alertedChannelId = msg['channelId']; | |
var messageId = parseInt(msg['messageId']); | |
var messageController = Packages.com.mirth.connect.server.controllers.messageController.getInstance(); | |
var message = messageController.getMessageContent(alertedChannelId, messageId, metaDataIds); | |
var sourceMessage = message.getConnectorMessages().get(0); | |
if(msg['errorType'] == 'Destination Connector'){ | |
var connectorName = msg['connector'] | |
var destinationId = sourceMessage.getDestinationIdMap().get(connectorName); | |
var destinationMessage = message.getConnectorMessages().get(destinationId); | |
var sendAttempts = destinationMessage.getSendAttempts(); | |
$c('sendAttempts', sendAttempts); | |
var tooManySendAttempts = (sendAttempts > parseInt($('sendAttemptsLimit'))); //TODO check if > or >= | |
$c('tooManySendAttempts', tooManySendAttempts); | |
var mirthMessageErrored = (destinationMessage.getStatus() == com.mirth.connect.donkey.model.message.Status.ERROR); | |
$c('mirthMessageErrored', mirthMessageErrored); | |
var mirthMessageSent = (destinationMessage.getStatus() == com.mirth.connect.donkey.model.message.Status.SENT); | |
$c('mirthMessageSent', mirthMessageSent); | |
shouldAlert = !mirthMessageSent && ( tooManySendAttempts || mirthMessageErrored ); | |
} | |
//should always alert for source messages | |
//should alert for destination messages that exceed send attempts limit | |
if(!shouldAlert){ | |
destinationSet.removeAll(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment