Skip to content

Commit 08b50d4

Browse files
authored
FIX(Status(NJS) remove syntax error (#3715)
* 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
1 parent 031faa0 commit 08b50d4

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/stats/nginx/njs/cache.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ function isLessThan24Hours(timestamp) {
1515
}
1616

1717
const DUMMY_DATA = {
18-
capacity: "32.74 PB",
19-
nodes: 2569,
20-
countries: 61,
21-
cores: 63968,
18+
capacity: "17.46 PB",
19+
ssd: "6800.54 TB",
20+
nodes: 2081,
21+
countries: 52,
22+
cores: 59828,
2223
};
2324
function readCache(path) {
2425
try {

packages/stats/nginx/njs/stats.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ let URLS = [
1313

1414
async function getStats(r) {
1515
const cachedData = cache.readCache(cache_path);
16+
if (!cachedData.valid || cachedData.error) {
17+
await updateStats(r);
18+
return;
19+
}
1620

1721
r.return(200, JSON.stringify(cachedData.summary));
1822
}
@@ -24,7 +28,9 @@ async function updateStats(r) {
2428
return;
2529
} catch (error) {
2630
r.error(`Failed to fetch stats: ${error}`);
27-
r.return(500, `Failed to fetch stats: ${error}`);
31+
r.error(`Returning cached data`);
32+
const cachedData = cache.readCache(cache_path);
33+
r.return(200, JSON.stringify(cachedData.summary));
2834
return;
2935
}
3036
}
@@ -131,7 +137,7 @@ function toTeraOrGiga(value) {
131137
return gb.toFixed(2) + " PB";
132138
}
133139

134-
export function toTeraOrGigaStats(value) {
140+
function toTeraOrGigaStats(value) {
135141
const giga = 1024 ** 3;
136142

137143
if (!value) return "0 GB";

0 commit comments

Comments
 (0)