安排任务每次运行一次1分钟和延迟

时间:2016-07-26 03:12:47

标签: javascript node.js cron scheduler

我在woeids.trends_country_capital中有一系列 35 Yahoo WOEIDs ,我想用它来获取各个WOEIDS的推特趋势。现在twitter的趋势API限制为1 req / min,所以我想以 1 / min 来获取35个WOEID的趋势,一旦完成所有将重复无限期

node module - cron

这是我从很多人那里测试过的一个代码,由于内部cron无法正常工作,因此肯定无法正常工作。我尝试过的另一个解决方案是将{strong> 35 位置拆分为三个cron作业15, 15, 5,但我无法理解如何让第一个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分钟。

0 个答案:

没有答案
相关问题