Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1.5 KB
Raw Blame
import { RuntimeEnvService } from '../app-config/runtime-env.service';
import { logError } from '../audit/audit-log.logger';
import { CronRegistrarService } from '../scheduling/cron-registrar.service';
import { AdminService } from './admin.service';
import { Injectable, type OnApplicationBootstrap } from '@nestjs/common';

/**
 * Daily version check (moved from src/scheduler.ts — it was the only consumer
 * of the old admin bridge, which died with the move). checkAndNotifyVersion
 * shares the module-scoped 5-minute cache in admin.helpers.ts with
 * GET /api/admin/version-check, so the cron and the route hit GitHub once
 * between them. No boot log — parity with the old starter.
 */
@Injectable()
export class VersionCheckJob implements OnApplicationBootstrap {
  constructor(
    private readonly admin: AdminService,
    private readonly registrar: CronRegistrarService,
    private readonly env: RuntimeEnvService,
  ) {}

  onApplicationBootstrap(): void {
    if (!this.registrar.isEnabled()) return;
    // A centrally administered install never registers it. The upgrade schedule
    // is the operator's, so the daily call to github.com would only ever produce
    // a notification telling the admin to do something they cannot do.
    if (this.env.isManaged()) return;
    this.registrar.register('version-check', '0 9 * * *', () => this.tick());
  }

  async tick(): Promise<void> {
    try {
      await this.admin.checkAndNotifyVersion();
    } catch (err: unknown) {
      logError(`Version check: ${err instanceof Error ? err.message : err}`);
    }
  }
}