Javascript 将任务安排为每次运行,每次运行1分钟并延迟一次
我在Javascript 将任务安排为每次运行,每次运行1分钟并延迟一次,javascript,node.js,cron,scheduler,Javascript,Node.js,Cron,Scheduler,我在WOEIDs.trends\u country\u capital中找到了一个由35个雅虎WOEIDs组成的数组,我想用它来获取各个WOEIDs的推特趋势。现在twitter的趋势API限制为1个请求/分钟,所以我想以1次/min的速度获取35个WOEID的趋势,一旦完成,就会无限期地重复这个过程 node module - cron 这里有一段代码我已经测试过很多次了,它肯定不会工作,因为内部cron不会工作。我尝试过的另一个解决方案是使用15、15、5将35位置拆分为三个cron作业,
WOEIDs.trends\u country\u capital
中找到了一个由35个雅虎WOEIDs组成的数组,我想用它来获取各个WOEIDs的推特趋势。现在twitter的趋势API限制为1个请求/分钟,所以我想以1次/min的速度获取35个WOEID的趋势,一旦完成,就会无限期地重复这个过程
node module - cron
这里有一段代码我已经测试过很多次了,它肯定不会工作,因为内部cron不会工作。我尝试过的另一个解决方案是使用15、15、5
将35位置拆分为三个cron作业,但我不明白如何让第一个cron作业等待。当我分开时,这就是我想要实现的流程:
const worldWide = new CronJob({
cronTime: '0 */35 * * * *',
onTick: function() {
_(woeids.trends_country_capital).forEach(woeid => {
new CronJob('0 */1 * * * *', function() {
trendsCountry.get('/trends/place', {id: woeid}, function(error, trends, response) {
if (!error) {
dbCountries.countries.update(
{ woeid: woeid },
{
woeid: woeid,
trends: trends[0].trends,
lastUpdated: new Date().getTime()
},
{ upsert: true },
function (err, data) {
console.log(err, data);
}
)
}
});
}, null, true, 'America/Los_Angeles');
});
},
start: false,
timeZone: 'America/Los_Angeles'
});
- 获取前15个WOEID趋势并等待35分钟再次执行
- 在使用上述cron 15分钟后获取接下来的15个趋势,并等待35分钟
- 在第二次作业15分钟后获取接下来的5个趋势,并等待35分钟