简体   繁体   中英

node.js `cron` module not working on heroku

I have cron module installed on my local machine, I deploying my app on heroku.

new cronJob('00 00 * * * *', function () {
    log.info('every hour');
}, null, true);

new cronJob('00 00 00 * * *', function () {
    log.info('every day');
}, null, true);

First cronJob executes log.info function every hour, and second - every day. Script works perfectly on my local machine, but not working on heroku.

Your cron job is never ran because Heroku dyno went to sleep. https://devcenter.heroku.com/articles/dynos#dyno-sleeping

Try waking it up by visiting some URL in your app and see if cron job gets executed.

In order to have your cron jobs executed you need to keep Heroku app awake 24/7. To make sure your Heroku app does not go to sleep, install the NewRelic Heroku Addon you can set up availability monitoring. You provide a URL which NewRelic pings every 30 seconds, therefore keeping your app awake. The intended purpose of this feature is to alert you if your site goes down for business and performance reasons, but it has the added benefit of preventing your app from idling.

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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