mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
fix(demo): save the first baseline only after a real seed again
Moving the first baseline save out of the boot-time seed into DemoResetJob also changed when it happened. The seed saved it only on the boot that put the example trips in; a later boot returned early and saved nothing, so an instance with data but no baseline logged "No baseline found, skipping" on every hourly reset. The job instead saved one on any demo boot that found no travel-baseline.db, freezing whatever the database held at that moment, user edits included, as the target the hourly reset rolls back to. The seed now leaves a mark when it seeds the example trips, and the job saves the first baseline only when that mark is set and no baseline exists, which is the old trigger. As before, the save does not depend on the cron registrar being enabled. The demo mode wiki page says so.
This commit is contained in:
@@ -5,7 +5,7 @@ import { RuntimeEnvService } from '../app-config/runtime-env.service';
|
||||
import { CronRegistrarService } from '../scheduling/cron-registrar.service';
|
||||
import { DATABASE_BACKUP, type DatabaseBackupStrategy } from '../database/database-backup.interface';
|
||||
import { withRequestContext } from '../database/request-context';
|
||||
import { hasBaseline, resetDemoUser, saveBaseline } from '../../demo/demo-reset';
|
||||
import { hasBaseline, resetDemoUser, saveBaseline, takeExampleTripsSeeded } from '../../demo/demo-reset';
|
||||
|
||||
/**
|
||||
* Demo mode: hourly reset of demo user data (moved from src/scheduler.ts).
|
||||
@@ -15,9 +15,12 @@ import { hasBaseline, resetDemoUser, saveBaseline } from '../../demo/demo-reset'
|
||||
* side-effect-free, and the close/swap/reopen sequence runs inside
|
||||
* resetDemoUser at tick time, through the injected backup port.
|
||||
*
|
||||
* It also saves the first baseline, on a demo boot that has none. That used to
|
||||
* happen inside the boot-time demo seed, which runs before the container can
|
||||
* hand anything in; here the port is injected like everywhere else.
|
||||
* It also saves the first baseline, on the boot whose seed has just put the
|
||||
* example trips in and only when no baseline exists yet: the same trigger the
|
||||
* save had inside the boot-time demo seed, which runs before the container can
|
||||
* hand the port in. A demo database that already holds data without a baseline
|
||||
* is left alone, so its hourly reset stays a logged no-op as before. Like the
|
||||
* old save, it does not depend on the cron registrar being enabled.
|
||||
*/
|
||||
@Injectable()
|
||||
export class DemoResetJob implements OnApplicationBootstrap {
|
||||
@@ -36,7 +39,7 @@ export class DemoResetJob implements OnApplicationBootstrap {
|
||||
this.registrar.register('demo-reset', '0 * * * *', () => void this.tick(), { timezone: 'none' });
|
||||
logInfo('Demo hourly reset scheduled');
|
||||
}
|
||||
if (!hasBaseline()) await this.saveFirstBaseline();
|
||||
if (takeExampleTripsSeeded() && !hasBaseline()) await this.saveFirstBaseline();
|
||||
}
|
||||
|
||||
async tick(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user