简体   繁体   English

如何在heroku上的多个worker dynos上构建计划任务,其中每个worker dyno都会继续执行一批不同的行

[英]How to build scheduled tasks on multiple worker dynos on heroku, where every worker dyno proceeds with a batch of different rows

I'm trying to build an application on heroku, and it's pretty clear how to add more worker dynos to finish the same task. 我正在尝试在heroku上构建一个应用程序,并且很清楚如何添加更多工作器dynos来完成相同的任务。

However, what i'm trying to do here is to create a cron job that runs multiple worker dynos where every one of them runs an incremental batch of tasks, imagine the following code: 但是,我在这里要做的是创建一个运行多个工作器dynos的cron作业,其中每个人都运行增量批量任务,想象下面的代码:

// those are variables coming from a cron
var limit;
var start;

connection.query("SELECT * FROM posts LIMIT " + limit + ", " + start, function(error, videos) {
    // do something
});

What I need to do here is as follows: create a clock worker, that runs a script every 2 hours, this should scale the worker dynos number up, pass to every one of them the limit and the start variables and scale back down when the tasks finish. 我需要做的是如下:创建一个每2个小时运行一个脚本的时钟工作者,这应该将工作人员的dynos数量调高,向他们每个人传递限制和启动变量并缩小时间任务完成。

I would really appreciate any help/guidance with that. 我真的很感激任何帮助/指导。

I haven't actually had to do this yet but its in my list of to-dos. 我实际上还没有这么做,但它在我的待办事项清单中。 At first glance I didn't see any way to do this with heroku but the solution that is looking most worthwhile is to build EC2 AMIs with Node running on a known port; 乍一看,我没有看到任何方法用heroku做到这一点,但看起来最有价值的解决方案是在已知端口上运行Node的情况下构建EC2 AMI; launch them with the scheduler and pass out jobs to the listening apps. 使用调度程序启动它们并将作业传递给侦听应用程序。 As long as you pass in the db connection string your EC2s will be able to pull info from your db and pass back results. 只要传入db连接字符串,EC2就能从数据库中提取信息并传回结果。

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

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