Skip to content

Instantly share code, notes, and snippets.

@benjaminudoh10
Last active January 4, 2023 10:33
Show Gist options
  • Save benjaminudoh10/9965aad9f8a5fa2563b77809b7a9cbfe to your computer and use it in GitHub Desktop.
Save benjaminudoh10/9965aad9f8a5fa2563b77809b7a9cbfe to your computer and use it in GitHub Desktop.

Revisions

  1. benjaminudoh10 revised this gist Jan 4, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions queue.service.ts
    Original file line number Diff line number Diff line change
    @@ -17,8 +17,8 @@ export default class QueueService {
    },
    connection: {
    // redis server connection options
    host: config.redis.host,
    port: config.redis.port,
    host: process.env.REDIS_HOST,
    port: process.env.REDIS_PORT,
    },
    };

  2. benjaminudoh10 created this gist Jan 4, 2023.
    44 changes: 44 additions & 0 deletions queue.service.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    import { Queue } from 'bullmq';

    enum Queues {
    DEFAULT = 'default',
    }

    export default class QueueService {
    private queues: Record<string, Queue>;
    private defaultQueue: Queue;

    private static instance: QueueService;

    private static QUEUE_OPTIONS = {
    defaultJobOptions: {
    removeOnComplete: false, // this indicates if the job should be removed from the queue once it's complete
    removeOnFail: false, // this indicates if the job should be removed from the queue if it fails
    },
    connection: {
    // redis server connection options
    host: config.redis.host,
    port: config.redis.port,
    },
    };

    constructor() {
    if (QueueService.instance instanceof QueueService) {
    return QueueService.instance;
    }

    this.queues = {};
    QueueService.instance = this;

    this.instantiateQueues();
    }

    async instantiateQueues() {
    this.defaultQueue = new Queue(Queues.DEFAULT, QueueService.QUEUE_OPTIONS);
    this.queues[Queues.DEFAULT] = this.defaultQueue;
    }

    getQueue(name: Queues) {
    return this.queues[name];
    }
    }