MCPcopy Create free account
hub / github.com/linuxfoundation/crowd.dev / handleMessages

Function handleMessages

backend/src/bin/nodejs-worker.ts:139–252  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

137}
138
139async function handleMessages() {
140 const handlerLogger = getChildLogger('messages', serviceLogger, {
141 queue: SQS_CONFIG.nodejsWorkerQueue,
142 })
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)

Callers 1

nodejs-worker.tsFile · 0.85

Calls 8

getChildLoggerFunction · 0.90
timeoutFunction · 0.90
isWorkerAvailableFunction · 0.85
receiveFunction · 0.85
addWorkerJobFunction · 0.85
processSingleMessageFunction · 0.85
infoMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected