File size: 1,005 Bytes
3206347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import process from 'process';
import { Queue } from 'bullmq';
import redisConfig from '../config/redis.js';
import logger from '../helpers/logger.js';

const CONNECTION_REFUSED = 'ECONNREFUSED';

const redisConnection = {
  connection: redisConfig,
};

const removeCancelledSubscriptionsQueue = new Queue(
  'remove-cancelled-subscriptions',
  redisConnection
);

process.on('SIGTERM', async () => {
  await removeCancelledSubscriptionsQueue.close();
});

removeCancelledSubscriptionsQueue.on('error', (error) => {
  if (error.code === CONNECTION_REFUSED) {
    logger.error(
      'Make sure you have installed Redis and it is running.',
      error
    );

    process.exit();
  }

  logger.error(
    'Error happened in remove cancelled subscriptions queue!',
    error
  );
});

removeCancelledSubscriptionsQueue.add('remove-cancelled-subscriptions', null, {
  jobId: 'remove-cancelled-subscriptions',
  repeat: {
    pattern: '0 1 * * *',
  },
});

export default removeCancelledSubscriptionsQueue;