Refactor queue management to use lazy initialization and improve Redis connection handling
- Updated queue and QueueEvents initialization to be lazy, preventing unnecessary Redis connections during the build process. - Refactored queue access methods to ensure consistent connection handling across the application. - Enhanced error handling for Redis connections during production builds to reduce log noise.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { ScheduledMessageDashboard, ScheduledMessageDashboardCreate } from '@nexumi/shared';
|
||||
import type { ScheduledMessage } from '@prisma/client';
|
||||
import { prisma } from '../prisma';
|
||||
import { scheduleQueue } from '../queues';
|
||||
import { getScheduleQueue } from '../queues';
|
||||
|
||||
export class SchedulerValidationError extends Error {
|
||||
constructor(public readonly code: string) {
|
||||
@@ -92,7 +92,7 @@ export async function createScheduledMessageDashboard(
|
||||
jobOptions.delay = Math.max(0, runAt.getTime() - Date.now());
|
||||
}
|
||||
|
||||
const job = await scheduleQueue.add('scheduleSend', { scheduleId: schedule.id }, jobOptions);
|
||||
const job = await getScheduleQueue().add('scheduleSend', { scheduleId: schedule.id }, jobOptions);
|
||||
const updated = await prisma.scheduledMessage.update({
|
||||
where: { id: schedule.id },
|
||||
data: { jobId: String(job.id) }
|
||||
@@ -108,7 +108,7 @@ export async function deleteScheduledMessageDashboard(guildId: string, scheduleI
|
||||
}
|
||||
|
||||
if (existing.jobId) {
|
||||
const job = await scheduleQueue.getJob(existing.jobId);
|
||||
const job = await getScheduleQueue().getJob(existing.jobId);
|
||||
await job?.remove();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user