简体   繁体   English

在Bull队列和数据库触发器之间选择

[英]Choosing between Bull queue and Database Triggers

I have a use case where I have to create a record in the database for users repeatedly on a scheduled basis. 我有一个用例,必须在数据库中定期为用户创建一条记录。 Let's say every Monday Weekly/BiWeekly. 假设每个星期一每周一次/每两周一次。 There are two ways with which i can achieve it. 我可以通过两种方式实现它。

  1. Using Database Triggers to Create a record on the time. 使用数据库触发器创建时间记录。 But I don't know how to repeat it. 但是我不知道该如何重复。 I have to create a trigger for the next schedule when this trigger runs, which i don't think is right approach. 当此触发器运行时,我必须为下一个计划创建一个触发器,我认为这不是正确的方法。

  2. Using Queues to handle the scheduling and executing the repeated jobs. 使用队列来处理调度和执行重复的作业。 But adding a job for each user is not a good idea I guess. 但是我想为每个用户添加工作并不是一个好主意。 I might be wrong but there is no other way to achieve my goal. 我可能是错的,但是没有其他方法可以实现我的目标。

I am confused on what to choose between the two. 我对两者之间的选择感到困惑。 Let's say i have to do this for 1 million users every week Monday at 9.00 am 假设我每周星期一上午9:00必须为100万用户执行此操作

Which approach will scale? 哪种方法可以扩展?

I am using nodejs as my backend and using Bull-Queue for the queue and postgres as my Database. 我正在使用nodejs作为后端,并使用Bull-Queue作为队列,并使用postgres作为数据库。

Using Database Triggers to Create a record on the time. 使用数据库触发器创建时间记录。 But I don't know how to repeat it. 但是我不知道该如何重复。 I have to create a trigger for the next schedule when this trigger runs, which i don't think is right approach. 当此触发器运行时,我必须为下一个计划创建一个触发器,我认为这不是正确的方法。 - Not a right approach based on the so many factors like - memory, number of requests and code quality. -基于诸如内存,请求数量和代码质量等众多因素的不正确方法。

So I went with the second approach: 因此,我采用了第二种方法:

Using Queues to handle the scheduling and executing the repeated jobs. 使用队列来处理调度和执行重复的作业。 But adding a job for each user is not a good idea I guess. 但是我想为每个用户添加工作并不是一个好主意。 I might be wrong but there is no other way to achieve my goal. 我可能是错的,但是没有其他方法可以实现我的目标。

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

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