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/maintenance-expired.js
Views: 687
1
#!/usr/bin/env node
2
/*
3
Delete expired rows in the database.
4
*/
5
6
const postgres = require("@cocalc/database");
7
8
const WAIT_BETWEEN_RUNS_S = process.env.WAIT_BETWEEN_RUNS_S ?? "7200";
9
const INTERVAL_MS = parseInt(WAIT_BETWEEN_RUNS_S) * 1000;
10
const db = postgres.db({ ensure_exists: false });
11
12
function delete_expired(cb) {
13
console.log("deleted_expired rows in database");
14
return db.delete_expired({ count_only: false, cb });
15
}
16
17
function go() {
18
console.log("go");
19
delete_expired(function (err) {
20
if (err) {
21
console.log(`failed to delete all expired rows -- ${err}`);
22
}
23
console.log(
24
`now waiting ${INTERVAL_MS} seconds before doing another delete...`
25
);
26
setTimeout(go, INTERVAL_MS);
27
});
28
}
29
30
go();
31
32