feat(queue): implement form-expiry-check maintenance job
Marks pending form_submissions whose expires_at has passed as 'expired'. Logs the count of rows transitioned each run. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import { Worker, type Job } from 'bullmq';
|
import { Worker, type Job } from 'bullmq';
|
||||||
|
import { and, eq, lt } from 'drizzle-orm';
|
||||||
|
|
||||||
import type { ConnectionOptions } from 'bullmq';
|
import type { ConnectionOptions } from 'bullmq';
|
||||||
|
import { db } from '@/lib/db';
|
||||||
|
import { formSubmissions } from '@/lib/db/schema/documents';
|
||||||
import { logger } from '@/lib/logger';
|
import { logger } from '@/lib/logger';
|
||||||
import { QUEUE_CONFIGS } from '@/lib/queue';
|
import { QUEUE_CONFIGS } from '@/lib/queue';
|
||||||
|
|
||||||
@@ -15,8 +18,14 @@ export const maintenanceWorker = new Worker(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'form-expiry-check': {
|
case 'form-expiry-check': {
|
||||||
// TODO(L3): mark expired form submissions
|
const result = await db
|
||||||
logger.info('Form expiry check — not yet implemented');
|
.update(formSubmissions)
|
||||||
|
.set({ status: 'expired' })
|
||||||
|
.where(
|
||||||
|
and(eq(formSubmissions.status, 'pending'), lt(formSubmissions.expiresAt, new Date())),
|
||||||
|
)
|
||||||
|
.returning({ id: formSubmissions.id });
|
||||||
|
logger.info({ expired: result.length }, 'Form expiry check complete');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user