Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
import { Worker, type Job } from 'bullmq';
|
2026-04-27 21:58:14 +02:00
|
|
|
import { and, eq, lt } from 'drizzle-orm';
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
|
|
|
|
|
import type { ConnectionOptions } from 'bullmq';
|
2026-04-27 21:58:14 +02:00
|
|
|
import { db } from '@/lib/db';
|
|
|
|
|
import { formSubmissions } from '@/lib/db/schema/documents';
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
import { logger } from '@/lib/logger';
|
|
|
|
|
import { QUEUE_CONFIGS } from '@/lib/queue';
|
|
|
|
|
|
|
|
|
|
export const maintenanceWorker = new Worker(
|
|
|
|
|
'maintenance',
|
|
|
|
|
async (job: Job) => {
|
|
|
|
|
logger.info({ jobId: job.id, jobName: job.name }, 'Processing maintenance job');
|
|
|
|
|
switch (job.name) {
|
|
|
|
|
case 'currency-refresh': {
|
|
|
|
|
const { refreshRates } = await import('@/lib/services/currency');
|
|
|
|
|
await refreshRates();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 'form-expiry-check': {
|
2026-04-27 21:58:14 +02:00
|
|
|
const result = await db
|
|
|
|
|
.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');
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
logger.warn({ jobName: job.name }, 'Unknown maintenance job');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
connection: { url: process.env.REDIS_URL! } as ConnectionOptions,
|
|
|
|
|
concurrency: QUEUE_CONFIGS.maintenance.concurrency,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
maintenanceWorker.on('failed', (job, err) => {
|
|
|
|
|
logger.error({ jobId: job?.id, jobName: job?.name, err }, 'Maintenance job failed');
|
|
|
|
|
});
|