Skip to content

Commit

Permalink
just want the errors to go away now
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Jones committed Aug 29, 2024
1 parent 0bcf6ba commit c174c01
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/mq/mqUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ async function connect() {
const connection = await amqp.connect(RABBITMQ_URL);
connection.on('error', (error) => {
logger.error('Error from RabbitMQ Connection:', formatError(error));
segment.addError(error);
if (segment) segment.addError(error);

});
const channel = await connection.createChannel();
channel.on('error', (error) => {
logger.error('Error from RabbitMQ Channel:', formatError(error));
segment.addError(error);
if (segment) segment.addError(error);

});

return { channel, connection };
} catch (error) {
logger.error('Failed to connect to RabbitMQ:', formatError(error));
segment.addError(error);
if (segment) segment.addError(error);
throw error;
} finally {
segment.close();
if (segment) segment.close();
}
}

Expand All @@ -56,18 +56,18 @@ const retryConnect = async (maxRetries = 5, delay = 1000) => {
for (let i = 0; i < maxRetries; i++) {
try {
const connectionData = await connect();
segment.close();
if (segment) segment.close();
return connectionData;
} catch (error) {
logger.error(`Retry ${i + 1}: Failed to connect to RabbitMQ`, formatError(error));
segment.addError(error);
if (segment) segment.addError(error);
await new Promise(resolve => setTimeout(resolve, delay));
delay *= 2;
}
}
const error = new Error('Exceeded max retries for connecting to RabbitMQ');
segment.addError(error);
segment.close();
if (segment) segment.addError(error);
if (segment) segment.close();
throw error;
};

Expand All @@ -85,10 +85,10 @@ async function createAndBindQueue(channel) {
return true;
} catch (error) {
logger.error("Error interacting with RabbitMQ:", formatError(error));
segment.addError(error);
if (segment) segment.addError(error);
return false;
}finally {
segment.close();
if (segment) segment.close();
}
}

Expand All @@ -106,13 +106,13 @@ async function listenToQueue(channel, callback) {
});
} catch (processingError) {
logger.error('Error processing message:', formatError(processingError));
subsegment.addError(processingError);
if (subsegment) subsegment.addError(processingError);
channel.nack(message);
} finally {
subsegment.close();
if (subsegment) subsegment.close();
}
}, { noAck: false });
segment.close();
if (segment) segment.close();
}

async function publishMessage(channel, message) {
Expand All @@ -124,10 +124,10 @@ async function publishMessage(channel, message) {
channel.publish('fanoutExchange', '', Buffer.from(JSON.stringify(message)));
} catch (publishError) {
logger.error('Error publishing message:', formatError(publishError));
segment.addError(publishError);
if (segment) segment.addError(publishError);
throw publishError;
} finally {
segment.close();
if (segment) segment.close();
}
}

Expand Down

0 comments on commit c174c01

Please sign in to comment.