UNPKG

smc-hub

Version:

CoCalc: Backend webserver component

31 lines (25 loc) 559 B
#!/usr/bin/env node /* Periodically update the stats in the database. */ const postgres = require("smc-hub/postgres"); const ttl = parseInt(process.env.STATS_TTL_S ?? "300"); const db = postgres.db({ ensure_exists: false, }); function update() { console.log("updating stats..."); db.get_stats({ update: true, ttl, cb(err, stats) { if (err) { throw Error(`failed to update stats -- ${err}`); } else { console.log("updated stats", stats); } setTimeout(update, ttl * 1000); }, }); } update();