opencode-statboard 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.js +32 -22
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -30,14 +30,17 @@ function compressFile(srcPath) {
|
|
|
30
30
|
const dstPath = srcPath + '.gz';
|
|
31
31
|
const src = fs.createReadStream(srcPath);
|
|
32
32
|
const dst = fs.createWriteStream(dstPath);
|
|
33
|
-
const gzip = zlib.createGzip({ level:
|
|
33
|
+
const gzip = zlib.createGzip({ level: 1 });
|
|
34
34
|
src.on('error', reject);
|
|
35
35
|
dst.on('error', reject);
|
|
36
|
+
gzip.on('error', reject);
|
|
36
37
|
dst.on('finish', () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
try {
|
|
39
|
+
const origSize = fs.statSync(srcPath).size;
|
|
40
|
+
const compSize = fs.statSync(dstPath).size;
|
|
41
|
+
fs.unlinkSync(srcPath);
|
|
42
|
+
resolve({ origSize, compSize });
|
|
43
|
+
} catch (e) { reject(e); }
|
|
41
44
|
});
|
|
42
45
|
src.pipe(gzip).pipe(dst);
|
|
43
46
|
});
|
|
@@ -797,6 +800,9 @@ process.on('SIGTERM', gracefulShutdown);
|
|
|
797
800
|
process.on('uncaughtException', (e) => { console.error('uncaught:', e); });
|
|
798
801
|
process.on('unhandledRejection', (e) => { console.error('unhandled:', e); });
|
|
799
802
|
|
|
803
|
+
// Keep process alive even if all timers are cleared
|
|
804
|
+
process.stdin.resume();
|
|
805
|
+
|
|
800
806
|
setInterval(() => {
|
|
801
807
|
try { cleanExpiredCache(trendCache, TREND_MS * 2); } catch (_) {}
|
|
802
808
|
try { cleanExpiredCache(reportCache, REPORT_TTL * 2); } catch (_) {}
|
|
@@ -828,22 +834,26 @@ function tryListen(port, maxPort) {
|
|
|
828
834
|
}
|
|
829
835
|
|
|
830
836
|
(async () => {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
837
|
+
try {
|
|
838
|
+
const actualPort = await tryListen(PORT, PORT + 5);
|
|
839
|
+
setInterval(refresh, REFRESH_MS);
|
|
840
|
+
setInterval(refreshModels, 60000);
|
|
841
|
+
await refresh();
|
|
842
|
+
await refreshModels();
|
|
843
|
+
for (const d of [1, 7, 30]) {
|
|
844
|
+
try {
|
|
845
|
+
const r = buildReportFromDb(d);
|
|
846
|
+
if (r && r.stats && r.stats.ok) reportCache[String(d)] = r;
|
|
847
|
+
} catch (_) {}
|
|
848
|
+
}
|
|
849
|
+
for (const d of [7, 30, 90]) {
|
|
850
|
+
try {
|
|
851
|
+
const t = await generateTrend(d);
|
|
852
|
+
if (t) trendCache[String(d)] = t;
|
|
853
|
+
} catch (_) {}
|
|
854
|
+
}
|
|
855
|
+
await autoBackupIfDue();
|
|
856
|
+
} catch (e) {
|
|
857
|
+
console.error('startup error:', e);
|
|
847
858
|
}
|
|
848
|
-
await autoBackupIfDue();
|
|
849
859
|
})();
|