Skip to content

Commit

Permalink
rename redisNotAvailableLogged, simplify conditional logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvyre committed Jan 21, 2020
1 parent 1a6c56e commit 16b6007
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/backend/lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const { logger } = require('../utils/logger');

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

/**
* Tracks whether an informative message has been logged following a Redis connection failure
*/
let redisConnectionRefusalLogged = false;

/**
* Create a Queue with the given `name` (String).
Expand All @@ -32,15 +36,13 @@ function createQueue(name) {
})
.on('error', err => {
// An error occurred
if (err.code === 'ECONNREFUSED') {
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;
}
if (err.code === 'ECONNREFUSED' && !redisConnectionRefusalLogged) {
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'
);
redisConnectionRefusalLogged = true;
} else {
logger.error({ err }, `Queue ${name} error`);
}
Expand Down

0 comments on commit 16b6007

Please sign in to comment.