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/delete-projects.js
Views: 687
1
#!/usr/bin/env node
2
/*
3
Periodically delete projects.
4
5
TODO: For now, this just calls the unlink function. Later on it
6
should do more (actually delete data, etc.).
7
*/
8
9
const postgres = require("@cocalc/database");
10
11
const INTERVAL_H = process.env.INTERVAL_H ?? "4";
12
const INTERVAL_MS = parseInt(INTERVAL_H) * 60 * 60 * 1000;
13
const db = postgres.db({ ensure_exists: false });
14
15
async function update() {
16
console.log("unlinking old deleted projects...");
17
try {
18
await db.unlink_old_deleted_projects();
19
} catch (err) {
20
if (err !== null) {
21
throw Error(`failed to unlink projects -- ${err}`);
22
} else {
23
console.log("unlink projects done");
24
}
25
}
26
console.log(`Waiting ${INTERVAL_H} hours...`);
27
setTimeout(update, INTERVAL_MS);
28
}
29
30
update();
31
32