I am running jobs from the 'node-schedule' module.
On localhost everything works great but when I upload to production in Heroku it doesn't.
i have changed my timezone in the settings -> var config to TZ at Asia/Jerusalem but it still doesn't work. Any idea why? Uploading my code although I think it is something with Heroku, not the code. Currently updating every minute just to test it, usefully its once every 1.5 hours
const schedule = require("node-schedule");
const needle = require("needle");
let j = schedule.scheduleJob("* /1 * * * *", function() {
needle.put("https://myserver.herokuapp.com/myendpoint");
});
Cronjobs can be run locally via npm package — node-cron. But in Heroku, Jobs scheduled by node_cron won't run when your free dynos are sleeping, that is if cron execution will be scheduled at the time when your server would be offline, then it won't work.
Installing the add-onNavigate to the “Resources” tab of the app's Dashboard. Search for “Heroku Scheduler” in the Add-ons search box. Follow the prompts to provision the Add-on.
Cron To Go is an add-on created for Heroku users to run scheduled jobs based on one-off dynos using cron expressions. Cron To Go combines the simplicity of using cron to schedule jobs with the scale and elasticity of the cloud.
I am successfully using cron jobs on Heroku and Azure with following code. I am using cron
import { CronJob } from 'cron';
const doSomething = new CronJob(
'0 0 * * 1', //cron time
fnname, //replace with your function that you want to call
null, //oncomplete
false, //start flag
'America/Los_Angeles',// timezone
);
doSomething.start()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With