Page 1 of 1

Cron sometimes doesn't fire

Posted: 01 Mar 2019 19:58
by piet66
Sometimes, in rare cases, cron doesn't fire. That's most annoying if heating remains cold or if irrigation is running whole night. It happened to me several times in last months.

One possible reason I found now:
From time to time execution of the timer is delayed for more than one minute. When a cron task has to be executed in this minute, it is skipped.

I proved this by adding some code to cron's index.js (see attached file), which checks this and writes a console message. And indeed I found this message in log file:

Code: Select all

[2019-02-28 20:23:15.092] [I] [core] Cron: tDelta=2 minutes, time reset to last minute +1
Solution may be: instead current minute take last minute + 1. I added this to the attached index.js.

I don't know the reason for these delays. My Raspi3 is only lightly loaded. But it happens. A Raspberry Pi is not a real-time process computer.

Re: Cron sometimes doesn't fire

Posted: 03 Mar 2019 10:14
by PoltoS
It is important to understand why is it blocking for so long. The JS engine is single thread and other threads are all locking each other.

So there should be something slowing down some thread. Do you have blocking HTTP requests or something else running in sync mode?

Re: Cron sometimes doesn't fire

Posted: 03 Mar 2019 12:32
by piet66
Nothing like that. I have no idea what's the reason.
But I think you always have to expect something like that. Maybe it happens more often without you noticing it. Even if you know the reason, it's not said that you can repair it.

Re: Cron sometimes doesn't fire

Posted: 03 Mar 2019 13:17
by PoltoS
In that case we should rather change it to something more generic. It might be delayed to more than 1 minute

Re: Cron sometimes doesn't fire

Posted: 03 Mar 2019 15:31
by piet66
No problem if you always take last stored minute + 1.

Re: Cron sometimes doesn't fire

Posted: 10 Mar 2019 12:31
by PoltoS
And if the delay was two minutes?

Re: Cron sometimes doesn't fire

Posted: 11 Mar 2019 20:46
by piet66
You are running the loop once per second. If you take each time the last used minute + 1, you will be after n seconds synchronized again, if delay was n minutes.
The trick is to store not the current minute but the last used minute.

Have you looked into my proposal in first post? It should run in this way.