CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/hub/run/stats-updater.js
Views: 687
1
#!/usr/bin/env node
2
3
/*
4
Periodically update the stats in the database.
5
*/
6
7
const postgres = require("@cocalc/database");
8
9
const ttl = parseInt(process.env.STATS_TTL_S ?? "300");
10
const db = postgres.db({
11
ensure_exists: false,
12
});
13
14
function update() {
15
console.log("updating stats...");
16
db.get_stats({
17
update: true,
18
ttl,
19
cb(err, stats) {
20
if (err) {
21
throw Error(`failed to update stats -- ${err}`);
22
} else {
23
console.log("updated stats", stats);
24
}
25
setTimeout(update, ttl * 1000);
26
},
27
});
28
}
29
30
update();
31
32