简体   繁体   中英

Node.js “node-cron” not running on Google app engine

I have configured this cronjobe using node-cron in my node.js project

const cron = require('node-cron');
cron.schedule('0 0 * * *', () => {

   console.log("CRON: Running");
   // Do someting

});

and deployed project to Google APP engine, this cron normally runs on my local during testing at 24:00 no issue, but on Google APP engine it is not...

Project itself normally deployed to server and running no issues (accessible through web) but cornjobe seems did not triggered at 24:00 by app engine server, i'm trying to understand why?? Seems server was off at moment when no one is using it, or??

This is because the App Engine instance is not necearily running at the time of the execution. (this happends more with Standard as it can scale down to 0)

Therefore a workaround for have Cronjobs in app engine is to have the schedule of this jobs managed by something else, in this case Google Cloud Scheduler which basically is a scheduler for tasks in app engine.

InThis Guide You can see how to create cron job with the cloud Scheduler by the cloud console.

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