47 lines
2.3 KiB
TypeScript
47 lines
2.3 KiB
TypeScript
// R-P5 (P5) §P2d — Apps-Engine maintenance crons: OAuth token refresh + health
|
|
// sweep. Config + idempotent scheduler registration only; the execution logic
|
|
// lives in handlers.ts (which holds the Prisma client), mirroring the task
|
|
// retention/reminder crons.
|
|
|
|
export const INTEGRATIONS_TOKEN_REFRESH_JOB_ID = "integrations-token-refresh" as const;
|
|
export const INTEGRATIONS_HEALTH_SWEEP_JOB_ID = "integrations-health-sweep" as const;
|
|
export const KWP_PROJECT_MAINTENANCE_JOB_ID = "kwp-project-maintenance" as const;
|
|
|
|
// KWP access tokens live for only five minutes. Sweep every minute so the
|
|
// KWP-specific two-minute refresh window has a real safety margin while the
|
|
// generic Apps-Engine refresh window remains unchanged.
|
|
export const INTEGRATIONS_TOKEN_REFRESH_EVERY_MS = 60 * 1000;
|
|
export const INTEGRATIONS_HEALTH_SWEEP_EVERY_MS = 15 * 60 * 1000;
|
|
export const KWP_PROJECT_MAINTENANCE_EVERY_MS = 15 * 60 * 1000;
|
|
|
|
/** Refresh tokens expiring within this window. Default 10 minutes. */
|
|
export const INTEGRATIONS_TOKEN_REFRESH_WINDOW_MINUTES = 10;
|
|
|
|
type SchedulerQueue = {
|
|
upsertJobScheduler: (schedulerId: string, options: { every: number }, template: { name: string; data?: Record<string, unknown> }) => Promise<unknown>;
|
|
};
|
|
|
|
export async function registerIntegrationsTokenRefreshCron(queue: SchedulerQueue): Promise<void> {
|
|
await queue.upsertJobScheduler(
|
|
INTEGRATIONS_TOKEN_REFRESH_JOB_ID,
|
|
{ every: INTEGRATIONS_TOKEN_REFRESH_EVERY_MS },
|
|
{ name: INTEGRATIONS_TOKEN_REFRESH_JOB_ID, data: { kind: "cleanup.run", task: INTEGRATIONS_TOKEN_REFRESH_JOB_ID, olderThanMinutes: INTEGRATIONS_TOKEN_REFRESH_WINDOW_MINUTES } },
|
|
);
|
|
}
|
|
|
|
export async function registerIntegrationsHealthSweepCron(queue: SchedulerQueue): Promise<void> {
|
|
await queue.upsertJobScheduler(
|
|
INTEGRATIONS_HEALTH_SWEEP_JOB_ID,
|
|
{ every: INTEGRATIONS_HEALTH_SWEEP_EVERY_MS },
|
|
{ name: INTEGRATIONS_HEALTH_SWEEP_JOB_ID, data: { kind: "cleanup.run", task: INTEGRATIONS_HEALTH_SWEEP_JOB_ID } },
|
|
);
|
|
}
|
|
|
|
export async function registerKwpProjectMaintenanceCron(queue: SchedulerQueue): Promise<void> {
|
|
await queue.upsertJobScheduler(
|
|
KWP_PROJECT_MAINTENANCE_JOB_ID,
|
|
{ every: KWP_PROJECT_MAINTENANCE_EVERY_MS },
|
|
{ name: KWP_PROJECT_MAINTENANCE_JOB_ID, data: { kind: "cleanup.run", task: KWP_PROJECT_MAINTENANCE_JOB_ID } },
|
|
);
|
|
}
|