Three audit-pass-#3 findings, all in the "wakes you at 3am" category.
- /api/public/health now runs DB SELECT 1 + Redis PING in parallel and
returns 503 + a degraded payload when either fails. Anonymous probes
(no X-Intake-Secret) still get a flat {status:'ok'} so generic uptime
monitors keep working; authenticated probes see the dep results.
- All worker entrypoints (ai, bulk, documents, email, export, import,
maintenance, notifications, reports, webhooks) and src/lib/redis.ts
now use env.REDIS_URL (Zod-validated at boot) instead of
process.env.REDIS_URL!. Previously a missing env let the app start
silently and fail at first job pickup.
- maintenance worker gains an `error-events-retention` case that
delete()s rows older than 90 days from error_events. scheduler.ts
registers it at 06:00 daily. Closes the contract from migration
0040 which declared the table "pruned at 90 days" but had no
implementation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { Worker, type Job } from 'bullmq';
|
|
import { env } from '@/lib/env';
|
|
|
|
import type { ConnectionOptions } from 'bullmq';
|
|
import { logger } from '@/lib/logger';
|
|
import { QUEUE_CONFIGS } from '@/lib/queue';
|
|
|
|
export const exportWorker = new Worker(
|
|
'export',
|
|
async (job: Job) => {
|
|
logger.info({ jobId: job.id, jobName: job.name }, 'Processing export job');
|
|
switch (job.name) {
|
|
case 'gdpr-export': {
|
|
const data = job.data as {
|
|
exportId: string;
|
|
portId: string;
|
|
clientId: string;
|
|
emailToClient: boolean;
|
|
emailOverride: string | null;
|
|
};
|
|
const { processGdprExportJob } = await import('@/lib/services/gdpr-export.service');
|
|
await processGdprExportJob(data);
|
|
break;
|
|
}
|
|
default:
|
|
logger.warn({ jobName: job.name }, 'Unknown export job');
|
|
}
|
|
},
|
|
{
|
|
connection: { url: env.REDIS_URL } as ConnectionOptions,
|
|
concurrency: QUEUE_CONFIGS.export.concurrency,
|
|
},
|
|
);
|
|
|
|
exportWorker.on('failed', (job, err) => {
|
|
logger.error({ jobId: job?.id, jobName: job?.name, err }, 'Export job failed');
|
|
});
|