node cron after Deploy not work But works on my machine

I use render to Deploy my server node cron does not work But works on my machine.

const job = new CronJob({
  //* * * * * every minute --- for Debugging
  //0 */6 * * * every 6 hours --- in production
  cronTime: "0 */6 * * *",
  onTick: function () {
    console.log("start crawling", new Date());
  },
  start: true,
});

async function startServer() {
  await mongoose.connect(process.env.MONGO);
  server.listen(PORT, () => {
    console.log(`Listening on ${PORT}...`);
  });
  job.start();
}

startServer();

I didn’t see the logs in render What should I do

Hi there,

Thanks for reaching out.

Cron jobs would be better suited to a Cron Job service or if you want to roll your own scheduler, a Background Worker. It looks like you’re trying to run it alongside a Web Service.

If you could share some more details that may help us troubleshoot it with you, e.g. any logs/errors/output, service ID, reproduction steps, etc. If you don’t want to share these details on the community forum, please feel free to raise a ticket with support@render.com

Kind regards

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.