(message: SqsMessage)
| 143 | handlerLogger.info('Listening for messages!') |
| 144 | |
| 145 | const processSingleMessage = async (message: SqsMessage): Promise<void> => { |
| 146 | await tracer.startActiveSpan('ProcessMessage', async (span) => { |
| 147 | const msg: NodeWorkerMessageBase = JSON.parse(message.Body) |
| 148 | |
| 149 | const messageLogger = getChildLogger('messageHandler', serviceLogger, { |
| 150 | messageId: message.MessageId, |
| 151 | type: msg.type, |
| 152 | }) |
| 153 | |
| 154 | try { |
| 155 | if ( |
| 156 | msg.type === NodeWorkerMessageType.NODE_MICROSERVICE && |
| 157 | (msg as any).service === 'enrich_member_organizations' |
| 158 | ) { |
| 159 | messageLogger.warn( |
| 160 | 'Skipping enrich_member_organizations message! Purging the queue because they are not needed anymore!', |
| 161 | ) |
| 162 | await removeFromQueue(message.ReceiptHandle) |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | messageLogger.info( |
| 167 | { messageType: msg.type, messagePayload: JSON.stringify(msg) }, |
| 168 | 'Received a new queue message!', |
| 169 | ) |
| 170 | |
| 171 | let processFunction: (msg: NodeWorkerMessageBase, logger?: Logger) => Promise<void> |
| 172 | |
| 173 | switch (msg.type) { |
| 174 | case NodeWorkerMessageType.INTEGRATION_PROCESS: |
| 175 | processFunction = processIntegration |
| 176 | break |
| 177 | case NodeWorkerMessageType.NODE_MICROSERVICE: |
| 178 | processFunction = processNodeMicroserviceMessage |
| 179 | break |
| 180 | case NodeWorkerMessageType.DB_OPERATIONS: |
| 181 | processFunction = processDbOperationsMessage |
| 182 | break |
| 183 | case NodeWorkerMessageType.PROCESS_WEBHOOK: |
| 184 | processFunction = processWebhook |
| 185 | break |
| 186 | |
| 187 | default: |
| 188 | messageLogger.error('Error while parsing queue message! Invalid type.') |
| 189 | } |
| 190 | |
| 191 | if (processFunction) { |
| 192 | await logExecutionTimeV2( |
| 193 | async () => { |
| 194 | // remove the message from the queue as it's about to be processed |
| 195 | await removeFromQueue(message.ReceiptHandle) |
| 196 | messagesInProgress.set(message.MessageId, msg) |
| 197 | try { |
| 198 | await processFunction(msg, messageLogger) |
| 199 | } catch (err) { |
| 200 | messageLogger.error(err, 'Error while processing queue message!') |
| 201 | } finally { |
| 202 | messagesInProgress.delete(message.MessageId) |
no test coverage detected