Cron sometimes doesn't fire

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
piet66
Posts: 266
Joined: 04 Feb 2017 17:00

Cron sometimes doesn't fire

Post 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.
Attachments
index.js.zip
(2.12 KiB) Downloaded 216 times
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v3.2.3 from 2022-04-06 04:56:23 +0300
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Cron sometimes doesn't fire

Post 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?
piet66
Posts: 266
Joined: 04 Feb 2017 17:00

Re: Cron sometimes doesn't fire

Post 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.
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v3.2.3 from 2022-04-06 04:56:23 +0300
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Cron sometimes doesn't fire

Post by PoltoS »

In that case we should rather change it to something more generic. It might be delayed to more than 1 minute
piet66
Posts: 266
Joined: 04 Feb 2017 17:00

Re: Cron sometimes doesn't fire

Post by piet66 »

No problem if you always take last stored minute + 1.
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v3.2.3 from 2022-04-06 04:56:23 +0300
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: Cron sometimes doesn't fire

Post by PoltoS »

And if the delay was two minutes?
piet66
Posts: 266
Joined: 04 Feb 2017 17:00

Re: Cron sometimes doesn't fire

Post 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.
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v3.2.3 from 2022-04-06 04:56:23 +0300
Post Reply