Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/hub/run/maintenance-blobs.js
Views: 687
#!/usr/bin/env node1/*2Delete expired rows in the database.3*/45const postgres = require("@cocalc/database");67const db = postgres.db({ ensure_exists: false });89let {10WAIT_BETWEEN_RUNS_S,11MAX_BLOBS_PER_RUN,12BLOBS_AT_ONCE,13COCALC_BLOB_STORE,14WAIT_BETWEEN_UPLOADS_S,15CUTOFF,16} = process.env;1718if (WAIT_BETWEEN_RUNS_S == null) {19WAIT_BETWEEN_RUNS_S = "120";20}21if (MAX_BLOBS_PER_RUN == null) {22MAX_BLOBS_PER_RUN = "2000";23}24if (BLOBS_AT_ONCE == null) {25BLOBS_AT_ONCE = "10";26}27if (COCALC_BLOB_STORE == null) {28COCALC_BLOB_STORE = "/blobs";29}30if (WAIT_BETWEEN_UPLOADS_S == null) {31WAIT_BETWEEN_UPLOADS_S = "0";32}33if (CUTOFF == null) {34CUTOFF = "2 months";35}3637function move_blobs_to_gcloud(cb) {38console.log(39`move_blobs_to_gcloud: copying up to ${MAX_BLOBS_PER_RUN} non-expiring blobs to bucket ${COCALC_BLOB_STORE} and deleting them from the database`40);41db.copy_all_blobs_to_gcloud({42bucket: COCALC_BLOB_STORE,43limit: parseInt(MAX_BLOBS_PER_RUN),44map_limit: parseInt(BLOBS_AT_ONCE),45repeat_until_done_s: 0,46remove: true,47throttle: parseFloat(WAIT_BETWEEN_UPLOADS_S),48cutoff: CUTOFF,49cb,50});51}5253function go() {54console.log("go");55move_blobs_to_gcloud(function (err) {56if (err) {57throw Error(`error in move_blobs_to_gcloud -- ${err}`);58}59console.log(60`now waiting ${WAIT_BETWEEN_RUNS_S} seconds before doing another move_blobs_to_gcloud...`61);62setTimeout(go, parseFloat(WAIT_BETWEEN_RUNS_S) * 1000);63});64}6566go();676869