Search code examples
queuenestjs

Implementing Bull Queue in nest js to send notification in the specification time?


I'm developing an application in nestjs, which manages queues in the bull. I have a queue that want to send notification in particular time (read from db). How can I implement this?


Solution

  • Not sure you manage to find out how to implement this using bull, but let me share if someone also having the same query.

    import { Queue, QueueScheduler } from 'bullmq';
    
    const myQueueScheduler = new QueueScheduler('Paint');
    const myQueue = new Queue('Paint');
    
    // Add a job that will be delayed at least 5 seconds.
    await myQueue.add('house', { color: 'white' }, { delay: 5000 });

    you can use the delay while adding the item into the queue. With the delay bull only trigger the notification processor from the current time.

    Ex: If you want to trigger notification after 1 hour you will calculate the millisecond delay based on the current time.