Skip to content

Commit 65453ee

Browse files
committed
enable automatic snapshots to happen
1 parent 9aaba83 commit 65453ee

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/packages/frontend/project/snapshots/edit-schedule.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ export default function EditSchedule() {
122122
{showHelp && (
123123
<p>
124124
Projects have rolling instant lightweight automatic snapshots of
125-
the exact state of your files. The parameters listed below
126-
determine how many of each timestamped snapshot is retained.
127-
Explicitly named snapshots that you manually create are not
128-
automatically deleted.
125+
the exact state of your files, which are created when you are
126+
actively using your project. The parameters listed below determine
127+
how many of each timestamped snapshot is retained. Explicitly
128+
named snapshots that you manually create are not automatically
129+
deleted.
129130
</p>
130131
)}
131132

src/packages/frontend/project_actions.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import {
9595
} from "@cocalc/frontend/project_store";
9696
import track from "@cocalc/frontend/user-tracking";
9797
import { webapp_client } from "@cocalc/frontend/webapp-client";
98-
import { once, retry_until_success } from "@cocalc/util/async-utils";
98+
import { once, retry_until_success, until } from "@cocalc/util/async-utils";
9999
import { DEFAULT_NEW_FILENAMES, NEW_FILENAMES } from "@cocalc/util/db-schema";
100100
import * as misc from "@cocalc/util/misc";
101101
import { reduxNameToProjectId } from "@cocalc/util/redux/name";
@@ -112,6 +112,7 @@ import { search } from "@cocalc/frontend/project/search/run";
112112
import { type CopyOptions } from "@cocalc/conat/files/fs";
113113
import { getFileTemplate } from "./project/templates";
114114
import { SNAPSHOTS } from "@cocalc/util/consts/snapshots";
115+
import { DEFAULT_SNAPSHOT_COUNTS } from "@cocalc/util/db-schema/projects";
115116

116117
const { defaults, required } = misc;
117118

@@ -366,6 +367,7 @@ export class ProjectActions extends Actions<ProjectStoreState> {
366367
this.initComputeServerManager();
367368
this.initComputeServersTable();
368369
this.initProjectStatus();
370+
this.initSnapshots();
369371
const store = this.get_store();
370372
store?.init_table("public_paths");
371373
};
@@ -393,6 +395,8 @@ export class ProjectActions extends Actions<ProjectStoreState> {
393395
return await webapp_client.project_client.api(this.project_id);
394396
}
395397

398+
isClosed = () => this.state == "closed";
399+
396400
destroy = (): void => {
397401
// console.log("destroy project actions", this.project_id);
398402
if (this.state == "closed") {
@@ -3517,4 +3521,40 @@ export class ProjectActions extends Actions<ProjectStoreState> {
35173521
setState({ search_error: `${err}` });
35183522
}
35193523
};
3524+
3525+
initSnapshots = reuseInFlight(async () => {
3526+
await until(
3527+
async () => {
3528+
if (this.isClosed()) return true;
3529+
const store = redux.getStore("projects");
3530+
if (store == null) {
3531+
return false;
3532+
}
3533+
const project = store.getIn(["project_map", this.project_id]);
3534+
if (project == null) {
3535+
return false;
3536+
}
3537+
const counts =
3538+
project.get("snapshots")?.toJS() ?? DEFAULT_SNAPSHOT_COUNTS;
3539+
if (counts.disabled) {
3540+
return false;
3541+
}
3542+
try {
3543+
await webapp_client.conat_client.hub.projects.updateSnapshots({
3544+
project_id: this.project_id,
3545+
counts,
3546+
});
3547+
} catch (err) {
3548+
console.warn(
3549+
`WARNING: Issue updating snapshots of ${this.project_id}`,
3550+
err,
3551+
{ counts },
3552+
);
3553+
}
3554+
return false;
3555+
},
3556+
// every 15 minutes
3557+
{ min: 60 * 1000 * 15, max: 60 * 1000 * 15 },
3558+
);
3559+
});
35203560
}

0 commit comments

Comments
 (0)