mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
724c88c201
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
52 lines
2.4 KiB
TypeScript
52 lines
2.4 KiB
TypeScript
import { AppSettings } from '../../db/entities/AppSettings.entity';
|
|
import { AppSettingsRepository } from '../../db/repositories/AppSettings.repository';
|
|
import { logInfo, logError } from '../audit/audit-log.logger';
|
|
import { readAppSetting } from '../common/app-settings.registry';
|
|
import { CronRegistrarService } from '../scheduling/cron-registrar.service';
|
|
import { AirtrailSyncService } from './airtrail-sync.service';
|
|
import { InjectRepository } from '@mikro-orm/nestjs';
|
|
import { Injectable, type OnApplicationBootstrap } from '@nestjs/common';
|
|
|
|
/**
|
|
* AirTrail sync: poll connected instances on an interval and reconcile linked
|
|
* flights both ways (#214). Moved from src/scheduler.ts. The per-tick enable
|
|
* gate (addon + setting) lives in runAirtrailSync, so toggling the addon takes
|
|
* effect without a restart; the poll interval is read once at bootstrap
|
|
* (parity — changing it still needs a restart).
|
|
*/
|
|
@Injectable()
|
|
export class AirtrailSyncJob implements OnApplicationBootstrap {
|
|
constructor(
|
|
@InjectRepository(AppSettings) private readonly appSettings: AppSettingsRepository,
|
|
private readonly airtrail: AirtrailSyncService,
|
|
private readonly registrar: CronRegistrarService,
|
|
) {}
|
|
|
|
async onApplicationBootstrap(): Promise<void> {
|
|
if (!this.registrar.isEnabled()) return;
|
|
// Through runOnBoot (task-6-review-parity.md C1 — the same shape whether
|
|
// the read below is raw SQL or, as of Plan 3h Task 4 (ATJ1), repository-
|
|
// backed: the wrap belongs at the entrypoint either way). minutes
|
|
// defaults to the same fallback the interval read itself falls back to,
|
|
// so an absent MikroORM (logged distinctly by runOnBoot, never silently)
|
|
// still registers the job at its default cadence rather than not
|
|
// registering at all.
|
|
let minutes = 5;
|
|
await this.registrar.runOnBoot('airtrail-sync-boot', async () => {
|
|
const value = await readAppSetting(this.appSettings, 'airtrail_poll_interval_minutes');
|
|
const raw = Number.parseInt(value || '5', 10);
|
|
minutes = Number.isFinite(raw) && raw >= 1 && raw <= 59 ? raw : 5;
|
|
logInfo(`AirTrail sync: scheduled every ${minutes}m`);
|
|
});
|
|
this.registrar.register('airtrail-sync', `*/${minutes} * * * *`, () => this.tick());
|
|
}
|
|
|
|
async tick(): Promise<void> {
|
|
try {
|
|
await this.airtrail.runAirtrailSync();
|
|
} catch (err: unknown) {
|
|
logError(`AirTrail sync tick failed: ${err instanceof Error ? err.message : err}`);
|
|
}
|
|
}
|
|
}
|