Check if Trello API is available before updating

This commit is contained in:
Jonathan Barrow 2021-10-18 22:30:53 -04:00
parent dee56c83e3
commit 60d70d1c8e
3 changed files with 2770 additions and 3 deletions

2761
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,7 @@
"express-handlebars": "^4.0.4",
"express-locale": "^2.0.0",
"fs-extra": "^9.1.0",
"got": "^11.8.2",
"gray-matter": "^4.0.3",
"ioredis": "^4.26.0",
"marked": "^3.0.4",

View File

@ -1,6 +1,7 @@
const Trello =require('trello');
const Redis = require('ioredis');
const JSONCache = require('redis-json');
const got = require('got');
const config = require('../config.json');
const trello = new Trello(config.trello.api_key, config.trello.api_token);
@ -14,7 +15,10 @@ async function getTrelloCache() {
}
if (cache.update_time < Date.now() - (1000 * 60 * 60)) {
cache = await updateTrelloCache();
const available = await trelloAPIAvailable();
if (available) {
cache = await updateTrelloCache();
}
}
return cache;
@ -64,6 +68,11 @@ async function updateTrelloCache() {
return progressData;
}
async function trelloAPIAvailable() {
const { status } = await got('https://trello.status.atlassian.com/api/v2/status.json').json();
return status.description === 'All Systems Operational';
}
module.exports = {
getTrelloCache,
updateTrelloCache