CognxSafeTrack commited on
Commit
bef7a3d
·
1 Parent(s): 25374b3

fix(redis): bypass ioredis minor version type mismatch and refactor scheduler

Browse files
apps/api/src/services/queue.ts CHANGED
@@ -12,7 +12,7 @@ const connection = process.env.REDIS_URL
12
  maxRetriesPerRequest: null
13
  });
14
 
15
- export const whatsappQueue = new Queue('whatsapp-queue', { connection });
16
 
17
  export async function scheduleMessage(userId: string, text: string, delayMs: number = 0) {
18
  await whatsappQueue.add('send-message', {
 
12
  maxRetriesPerRequest: null
13
  });
14
 
15
+ export const whatsappQueue = new Queue('whatsapp-queue', { connection: connection as any });
16
 
17
  export async function scheduleMessage(userId: string, text: string, delayMs: number = 0) {
18
  await whatsappQueue.add('send-message', {
apps/whatsapp-worker/src/index.ts CHANGED
@@ -185,7 +185,7 @@ const worker = new Worker('whatsapp-queue', async (job: Job) => {
185
  console.error(`Job ${job.id} failed:`, error);
186
  throw error;
187
  }
188
- }, { connection });
189
 
190
  console.log('WhatsApp Worker started...');
191
 
 
185
  console.error(`Job ${job.id} failed:`, error);
186
  throw error;
187
  }
188
+ }, { connection: connection as any });
189
 
190
  console.log('WhatsApp Worker started...');
191
 
apps/whatsapp-worker/src/scheduler.ts CHANGED
@@ -3,12 +3,20 @@ import { Queue } from 'bullmq';
3
  import { PrismaClient } from '@prisma/client';
4
 
5
  const prisma = new PrismaClient();
6
- const connection = {
7
- host: process.env.REDIS_HOST || 'localhost',
8
- port: parseInt(process.env.REDIS_PORT || '6379'),
9
- };
 
 
 
 
 
 
 
 
10
 
11
- const whatsappQueue = new Queue('whatsapp-queue', { connection });
12
 
13
  export function startDailyScheduler() {
14
  // Runs at 08:00 AM every day
 
3
  import { PrismaClient } from '@prisma/client';
4
 
5
  const prisma = new PrismaClient();
6
+ import Redis from 'ioredis';
7
+
8
+ const connection = process.env.REDIS_URL
9
+ ? new Redis(process.env.REDIS_URL, { maxRetriesPerRequest: null })
10
+ : new Redis({
11
+ host: process.env.REDIS_HOST || 'localhost',
12
+ port: parseInt(process.env.REDIS_PORT || '6379'),
13
+ username: process.env.REDIS_USERNAME || 'default',
14
+ password: process.env.REDIS_PASSWORD || undefined,
15
+ tls: process.env.REDIS_TLS === 'true' ? {} : undefined,
16
+ maxRetriesPerRequest: null
17
+ });
18
 
19
+ const whatsappQueue = new Queue('whatsapp-queue', { connection: connection as any });
20
 
21
  export function startDailyScheduler() {
22
  // Runs at 08:00 AM every day