Skip to content

Commit

Permalink
better autosaving logic, phetsims/scenery-phet#890
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jan 13, 2025
1 parent d0d7ae1 commit 49193f3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions js/server/ContinuousServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ const daysToMS = days => hoursToMS( days * 24 );
const twoHours = hoursToMS( 2 );
const twelveHours = hoursToMS( 12 );

const jsonExtension = '.json';

class ContinuousServer {
/**
* @param {boolean} useRootDir - If true, we won't create/copy, and we'll just use the files there instead
Expand All @@ -81,7 +79,7 @@ class ContinuousServer {
this.rootDir = path.normalize( `${__dirname}/../../../` );

// @public {string} - Where we'll load/save our state
this.saveFile = `${this.rootDir}/aqua/.continuous-testing-state${jsonExtension}`;
this.saveFile = `${this.rootDir}/aqua/.continuous-testing-state.json`;

// @public {Array.<Snapshot>} - All of our snapshots
this.snapshots = [];
Expand Down Expand Up @@ -133,7 +131,7 @@ class ContinuousServer {
'SIGSEGV', 'SIGUSR2', 'SIGTERM', 'beforeExit', 'uncaughtException', 'unhandledRejection'
].forEach( sig => process.on( sig, () => {
winston.info( 'saving forcefully before exiting' );
this.saveToFile( true, true );
this.saveToFile( true );
process.exit( 1 );
} ) );
}
Expand Down Expand Up @@ -345,7 +343,7 @@ class ContinuousServer {
* Saves the state of snapshots to our save file.
* @public
*/
saveToFile( force = false, withBackup = false ) {
saveToFile( force = false ) {
// Don't save or load state if useRootDir is true
if ( this.useRootDir ) {
return;
Expand All @@ -366,7 +364,6 @@ class ContinuousServer {
pendingSnapshot: this.pendingSnapshot ? this.pendingSnapshot.serializeStub() : null,
trashSnapshots: this.trashSnapshots.map( snapshot => snapshot.serializeStub() )
}, null, 2 );
withBackup && fs.writeFileSync( this.saveFile.replace( jsonExtension, `-backup${jsonExtension}` ), data, 'utf-8' );
fs.writeFileSync( this.saveFile, data, 'utf-8' );

this.saveFileLocked = false;
Expand Down Expand Up @@ -828,6 +825,7 @@ class ContinuousServer {
}
catch( e ) {
this.setError( `autosave error: ${e} ${e.stack}` );
this.saveFileLocked = false; // unlock the file so we can try again
}
await sleep( minutesToMS( 5 ) ); // Run this every 5 minutes
}
Expand Down

2 comments on commit 49193f3

@samreid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zepumph was this commit intended for #231?

@zepumph
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yup thanks.

Please sign in to comment.