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-syncstrings.js
Views: 687
1
#!/usr/bin/env node
2
/*
3
Moving patches from non-recently-used syncstrings to blobs.
4
*/
5
6
const postgres = require("@cocalc/database");
7
8
const db = postgres.db({ ensure_exists: false });
9
10
let {
11
WAIT_BETWEEN_RUNS_S,
12
MAX_SYNCSTRINGS_PER_RUN,
13
SYNCSTRINGS_AT_ONCE,
14
MIN_AGE_DAYS,
15
DELAY_MS,
16
} = process.env;
17
18
if (WAIT_BETWEEN_RUNS_S == null) {
19
WAIT_BETWEEN_RUNS_S = "30";
20
}
21
if (MAX_SYNCSTRINGS_PER_RUN == null) {
22
MAX_SYNCSTRINGS_PER_RUN = "100";
23
}
24
if (SYNCSTRINGS_AT_ONCE == null) {
25
SYNCSTRINGS_AT_ONCE = "1";
26
}
27
if (MIN_AGE_DAYS == null) {
28
MIN_AGE_DAYS = "60.5";
29
}
30
if (DELAY_MS == null) {
31
DELAY_MS = "5000";
32
}
33
34
function syncstring_maintenance(cb) {
35
console.log(
36
`syncstring_maintenance: moving patches for up to ${MAX_SYNCSTRINGS_PER_RUN} syncstrings at least ${MIN_AGE_DAYS} days old to compressed blobs...`
37
);
38
db.syncstring_maintenance({
39
limit: parseInt(MAX_SYNCSTRINGS_PER_RUN),
40
map_limit: parseInt(SYNCSTRINGS_AT_ONCE),
41
age_days: parseFloat(MIN_AGE_DAYS),
42
delay: parseInt(DELAY_MS),
43
repeat_until_done: false,
44
cb,
45
});
46
}
47
48
function go() {
49
console.log("go");
50
syncstring_maintenance(function (err) {
51
if (err) {
52
throw Error(`error in syncstring_maintenance -- ${err}`);
53
}
54
console.log(
55
`now waiting ${WAIT_BETWEEN_RUNS_S} seconds before doing another syncstring_maintenance...`
56
);
57
setTimeout(go, parseInt(WAIT_BETWEEN_RUNS_S) * 1000);
58
});
59
}
60
61
go();
62
63