Skip to content

Commit

Permalink
FIX(Status(NJS) remove syntax error (#3715)
Browse files Browse the repository at this point in the history
* FIX(Status(NJS) remove syntax error

* CHORE(stats): update dummy data

* feat(Status): update status in case of cache is invalid or there is an error

* feat(Status): return cached data in case of updateStats failed with 304 code

* fix: remove 304 as the body is required
  • Loading branch information
0oM4R authored Dec 8, 2024
1 parent 031faa0 commit 08b50d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/stats/nginx/njs/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ function isLessThan24Hours(timestamp) {
}

const DUMMY_DATA = {
capacity: "32.74 PB",
nodes: 2569,
countries: 61,
cores: 63968,
capacity: "17.46 PB",
ssd: "6800.54 TB",
nodes: 2081,
countries: 52,
cores: 59828,
};
function readCache(path) {
try {
Expand Down
10 changes: 8 additions & 2 deletions packages/stats/nginx/njs/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ let URLS = [

async function getStats(r) {
const cachedData = cache.readCache(cache_path);
if (!cachedData.valid || cachedData.error) {
await updateStats(r);
return;
}

r.return(200, JSON.stringify(cachedData.summary));
}
Expand All @@ -24,7 +28,9 @@ async function updateStats(r) {
return;
} catch (error) {
r.error(`Failed to fetch stats: ${error}`);
r.return(500, `Failed to fetch stats: ${error}`);
r.error(`Returning cached data`);
const cachedData = cache.readCache(cache_path);
r.return(200, JSON.stringify(cachedData.summary));
return;
}
}
Expand Down Expand Up @@ -131,7 +137,7 @@ function toTeraOrGiga(value) {
return gb.toFixed(2) + " PB";
}

export function toTeraOrGigaStats(value) {
function toTeraOrGigaStats(value) {
const giga = 1024 ** 3;

if (!value) return "0 GB";
Expand Down

0 comments on commit 08b50d4

Please sign in to comment.