Cronjob stops working after period of time

Hello,

  1. My goal is: To have a cronjob fire on an esp8266 every minute reliably.

  2. My actions are: I’ve set up a cronjob on boot of the device:

     mgos_cron_id_t light_timer_cron_id;
     void setup_cron_job()
     {
         // We want a cron job every minute so 0 */1 * * * *
         light_timer_cron_id = mgos_cron_add("0 */1 * * * *", cron_job_minute_cb, NULL);
     }
    
  3. The result I see is: It works for a short time (a couple of minutes to some hours) after this the cronjob no longer fires. I get no errors or logs that inform me why it has stopped.

  4. My expectation & question is: How can I make sure that the cronjob keeps on working, and what can cause the mechanism to fail? Alternatively, can I easily detect this and restart the job?

Could you provide an example to reproduce this issue?
I’m running a few devices with 1 minute cron jobs that work without any problem.

I have run into this problem with cron jobs and mongoose-os timers as well. Cron Jobs are based on timers, so I think the root cause is in the timer code somewhere. I have come across many instances where a timer just doesn’t fire, whether it be a continuous led blinking timer, or a cron job set to do something more. Here is an old forum post that never seemed to be resolved.

https://forum.mongoose-os.com/discussion/1501/timer-code-not-run-randomly

I unfortunately could not help with the esp8266, however I switched all my critical timers to use Hardware timers on the ESP32. ESP32 is limited to 4 hardware timers. I also modified the cron library source code to reuse 1 hardware timer (instead of multiple software timers) for all cron jobs. These hardware timers are 100% more reliable in my application, but because they are set with microseconds instead of milliseconds, you need to set them no longer than 35 minutes out. I implemented a “reschedule timer” every 30 minutes that checks all pending cron jobs and sets the soonest one to use the hardware timer, if within 30 minutes.

If I am not mistaken this code is licensed only so I can not share without permission.