Skip to content

Commit

Permalink
Ensure redis connection error is logged only once
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvyre committed Jan 19, 2020
1 parent ffcebe5 commit 1a6c56e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/backend/lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { logger } = require('../utils/logger');

const client = createRedisClient();
const subscriber = createRedisClient();
let redisErrorLogged = false;

/**
* Create a Queue with the given `name` (String).
Expand All @@ -32,11 +33,14 @@ function createQueue(name) {
.on('error', err => {
// An error occurred
if (err.code === 'ECONNREFUSED') {
logger.error(
'\n\n\t💡 It appears that Redis is not running on your machine.',
'\n\t Please see our documentation for how to install and run Redis:',
'\n\t https://github.com/Seneca-CDOT/telescope/blob/master/docs/CONTRIBUTING.md\n'
);
if (!redisErrorLogged) {
logger.error(
'\n\n\t💡 It appears that Redis is not running on your machine.',
'\n\t Please see our documentation for how to install and run Redis:',
'\n\t https://github.com/Seneca-CDOT/telescope/blob/master/docs/CONTRIBUTING.md\n'
);
redisErrorLogged = true;
}
} else {
logger.error({ err }, `Queue ${name} error`);
}
Expand Down

0 comments on commit 1a6c56e

Please sign in to comment.