gpt4 book ai didi

javascript - 在 Bull 队列和数据库触发器之间进行选择

转载 作者:行者123 更新时间:2023-11-29 13:41:30 34 4
gpt4 key购买 nike

我有一个用例,我必须定期在数据库中为用户重复创建一条记录。假设每个星期一每周/每两周一次。我可以通过两种方式实现它。

  1. 使用数据库触发器在时间上创建记录。但我不知道如何重复它。当此触发器运行时,我必须为下一个计划创建一个触发器,我认为这是不正确的方法。

  2. 使用队列来处理调度和执行重复的作业。但我想为每个用户添加一份工作并不是一个好主意。我可能是错的,但没有其他方法可以实现我的目标。

我对在两者之间做出选择感到困惑。假设我必须在每周一上午 9 点为 100 万用户执行此操作。

哪种方法可以扩展?

我使用 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.

所以我采用了第二种方法:

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.

关于javascript - 在 Bull 队列和数据库触发器之间进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54730530/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com