简体   繁体   English

在nest js中实现Bull Queue以在规范时间内发送通知?

[英]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.我正在用nestjs 开发一个应用程序,它管理公牛中的队列。 I have a queue that want to send notification in particular time (read from db).我有一个想要在特定时间发送通知的队列(从数据库读取)。 How can I implement this?我该如何实施?

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.例如:如果您想在 1 小时后触发通知,您将根据当前时间计算毫秒延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM