All files / src/services queues.server.ts

96.92% Statements 126/130
56.25% Branches 9/16
100% Functions 0/0
96.69% Lines 117/121

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 1222x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 10x 2x 2x 2x 2x 70x 2x 2x 7x 7x 2x 2x 2x 2x 7x 7x 70x 2x 2x 9x 2x 2x 2x 5x 5x 5x 5x 70x 1x 1x 2x 2x 2x     2x 2x 2x     70x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 70x 2x 2x 2x 2x 2x 2x 2x 2x 70x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 70x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 70x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 70x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x  
import { Queue } from 'bullmq';
import { connection } from './redis.server';
import type {
  FlyerJobData,
  EmailJobData,
  AnalyticsJobData,
  WeeklyAnalyticsJobData,
  CleanupJobData,
  TokenCleanupJobData,
  ReceiptJobData,
  ExpiryAlertJobData,
  BarcodeDetectionJobData,
} from '../types/job-data';
 
// --- Queues ---
 
export const flyerQueue = new Queue<FlyerJobData>('flyer-processing', {
  connection,
  defaultJobOptions: {
    attempts: 3,
    backoff: {
      type: 'exponential',
      delay: 5000,
    },
  },
});
 
export const emailQueue = new Queue<EmailJobData>('email-sending', {
  connection,
  defaultJobOptions: {
    attempts: 5,
    backoff: {
      type: 'exponential',
      delay: 10000,
    },
  },
});
 
export const analyticsQueue = new Queue<AnalyticsJobData>('analytics-reporting', {
  connection,
  defaultJobOptions: {
    attempts: 2,
    backoff: {
      type: 'exponential',
      delay: 60000,
    },
    removeOnComplete: true,
    removeOnFail: 50,
  },
});

export const weeklyAnalyticsQueue = new Queue<WeeklyAnalyticsJobData>(
  'weekly-analytics-reporting',
  {
    connection,
    defaultJobOptions: {
      attempts: 2,
      backoff: { type: 'exponential', delay: 3600000 },
      removeOnComplete: true,
      removeOnFail: 50,
    },
  },
);
 
export const cleanupQueue = new Queue<CleanupJobData>('file-cleanup', {
  connection,
  defaultJobOptions: {
    attempts: 3,
    backoff: { type: 'exponential', delay: 30000 },
    removeOnComplete: true,
  },
});
 
export const tokenCleanupQueue = new Queue<TokenCleanupJobData>('token-cleanup', {
  connection,
  defaultJobOptions: {
    attempts: 2,
    backoff: { type: 'exponential', delay: 3600000 },
    removeOnComplete: true,
    removeOnFail: 10,
  },
});
 
// --- Receipt Processing Queue ---
export const receiptQueue = new Queue<ReceiptJobData>('receipt-processing', {
  connection,
  defaultJobOptions: {
    attempts: 3,
    backoff: {
      type: 'exponential',
      delay: 10000, // 10 seconds initial delay
    },
    removeOnComplete: 100, // Keep last 100 completed jobs
    removeOnFail: 50,
  },
});
 
// --- Expiry Alert Queue ---
export const expiryAlertQueue = new Queue<ExpiryAlertJobData>('expiry-alerts', {
  connection,
  defaultJobOptions: {
    attempts: 2,
    backoff: { type: 'exponential', delay: 300000 }, // 5 minutes
    removeOnComplete: true,
    removeOnFail: 20,
  },
});
 
// --- Barcode Detection Queue ---
export const barcodeQueue = new Queue<BarcodeDetectionJobData>('barcode-detection', {
  connection,
  defaultJobOptions: {
    attempts: 2,
    backoff: {
      type: 'exponential',
      delay: 5000,
    },
    removeOnComplete: 50,
    removeOnFail: 20,
  },
});