Skip to content

Commit

Permalink
Merge pull request #1007 from manekenpix/eslint-warnings
Browse files Browse the repository at this point in the history
Fixed eslint warnings
  • Loading branch information
manekenpix authored Apr 15, 2020
2 parents 038769b + f7b3529 commit 24b7abc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"pino": "6.2.0",
"pino-pretty": "4.0.0",
"sanitize-html": "1.23.0",
"set-interval-async": "1.0.32",
"stoppable": "1.1.0",
"valid-url": "1.0.9"
},
Expand Down
14 changes: 9 additions & 5 deletions src/backend/utils/elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require('../lib/config');

const { ELASTIC_URL, ELASTIC_PORT, ELASTIC_MAX_RESULTS } = process.env;
const { Client } = require('@elastic/elasticsearch');
const { setIntervalAsync, clearIntervalAsync } = require('set-interval-async/dynamic');

const elasticUrl = `${ELASTIC_URL}:${ELASTIC_PORT}` || 'http://localhost:9200';
const esClient = new Client({ node: elasticUrl });
Expand Down Expand Up @@ -111,16 +112,19 @@ const waitOnReady = async () => {
});

const connectivity = new Promise((resolve) => {
intervalId = setInterval(() => {
checkConnection()
.then(resolve)
.catch(() => logger.info('Attempting to connect to elasticsearch...'));
intervalId = setIntervalAsync(async () => {
try {
await checkConnection();
resolve();
} catch (error) {
logger.info('Attempting to connect to elasticsearch...');
}
}, 500);
});

await Promise.race([timer, connectivity]);

clearInterval(intervalId);
await clearIntervalAsync(intervalId);
clearTimeout(timerId);
};

Expand Down
16 changes: 10 additions & 6 deletions src/backend/utils/wiki-feed-parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fetch = require('node-fetch');
const jsdom = require('jsdom');
const { isWebUri } = require('valid-url');
const { setIntervalAsync, clearIntervalAsync } = require('set-interval-async/dynamic');

require('../lib/config');
const { logger } = require('./logger');
Expand Down Expand Up @@ -38,7 +39,8 @@ async function getWikiText(url) {
*/
module.exports = async function () {
let url = process.env.FEED_URL;
const interval = process.env.FEED_URL_INTERVAL_MS || 30000;
// without parseInt(), setIntervalAsync fails, possibly because it takes the value in interval as a string
const interval = parseInt(process.env.FEED_URL_INTERVAL_MS || 30000, 10);

if (!url) {
url = 'https://wiki.cdot.senecacollege.ca/wiki/Planet_CDOT_Feed_List';
Expand All @@ -54,16 +56,18 @@ module.exports = async function () {
*/
let intervalId;
const downloadFeedList = new Promise((resolve) => {
intervalId = setInterval(() => {
getWikiText(url)
.then(resolve)
.catch((error) => logger.info({ error }));
intervalId = setIntervalAsync(async () => {
try {
resolve(await getWikiText(url));
} catch (error) {
logger.error({ error });
}
}, interval);
});

const wikiText = await downloadFeedList;

clearInterval(intervalId);
await clearIntervalAsync(intervalId);

const lines = wikiText.split(/\r\n|\r|\n/);
const feeds = [];
Expand Down

0 comments on commit 24b7abc

Please sign in to comment.