@@ -95,7 +95,7 @@ import {
95
95
} from "@cocalc/frontend/project_store" ;
96
96
import track from "@cocalc/frontend/user-tracking" ;
97
97
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" ;
99
99
import { DEFAULT_NEW_FILENAMES , NEW_FILENAMES } from "@cocalc/util/db-schema" ;
100
100
import * as misc from "@cocalc/util/misc" ;
101
101
import { reduxNameToProjectId } from "@cocalc/util/redux/name" ;
@@ -112,6 +112,7 @@ import { search } from "@cocalc/frontend/project/search/run";
112
112
import { type CopyOptions } from "@cocalc/conat/files/fs" ;
113
113
import { getFileTemplate } from "./project/templates" ;
114
114
import { SNAPSHOTS } from "@cocalc/util/consts/snapshots" ;
115
+ import { DEFAULT_SNAPSHOT_COUNTS } from "@cocalc/util/db-schema/projects" ;
115
116
116
117
const { defaults, required } = misc ;
117
118
@@ -366,6 +367,7 @@ export class ProjectActions extends Actions<ProjectStoreState> {
366
367
this . initComputeServerManager ( ) ;
367
368
this . initComputeServersTable ( ) ;
368
369
this . initProjectStatus ( ) ;
370
+ this . initSnapshots ( ) ;
369
371
const store = this . get_store ( ) ;
370
372
store ?. init_table ( "public_paths" ) ;
371
373
} ;
@@ -393,6 +395,8 @@ export class ProjectActions extends Actions<ProjectStoreState> {
393
395
return await webapp_client . project_client . api ( this . project_id ) ;
394
396
}
395
397
398
+ isClosed = ( ) => this . state == "closed" ;
399
+
396
400
destroy = ( ) : void => {
397
401
// console.log("destroy project actions", this.project_id);
398
402
if ( this . state == "closed" ) {
@@ -3517,4 +3521,40 @@ export class ProjectActions extends Actions<ProjectStoreState> {
3517
3521
setState ( { search_error : `${ err } ` } ) ;
3518
3522
}
3519
3523
} ;
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
+ } ) ;
3520
3560
}
0 commit comments