Dealer_Onboarding_Backend/src/common/queues/offboarding-lwd.queue.ts

29 lines
948 B
TypeScript

import { Queue } from 'bullmq';
import { redisConfig } from './config.js';
export const offboardingLwdQueue = new Queue('offboardingLwdQueue', {
connection: redisConfig
});
/**
* Daily sweep (08:00) + optional per-case delayed jobs when a case enters Awaiting F&F.
*/
export const scheduleOffboardingLwdReminders = async () => {
const isFastMode = process.env.DEBUG_OFFBOARDING_LWD_FAST_MODE === 'true';
const pattern = isFastMode ? '*/15 * * * *' : '0 8 * * *';
const jobs = await offboardingLwdQueue.getRepeatableJobs();
for (const job of jobs) {
await offboardingLwdQueue.removeRepeatableByKey(job.key);
}
await offboardingLwdQueue.add('checkLwdFnfReminders', {}, {
repeat: { pattern },
jobId: 'offboarding-lwd-fnf-reminder'
});
console.log(
`[Offboarding LWD Queue] Repeatable job scheduled: ${isFastMode ? 'Every 15 minutes (FAST MODE)' : 'Daily at 08:00'}`
);
};