I have an app that has a routine that I run every minute using runEvery1Minute. Works fine but I would like to run it every 15 seconds. There doesn’t seem to be a runEvery shorter than 1 minute. How would I do that?
You would use schedule() with a cron string specifying whatever schedule you want:
However, 15 seconds is pretty frequent. Is this a lightweight task, and does your app really have a need to do this on such a frequent, time-based interval, or would something like an event subscription be a better idea?
I looked at that but was under the impression that that just selected which second of each minute. I’ll revisit. All I’m doing is cycling color on a bulb. So not much going on.
You could try using runIn(), but will need to call it each time the routine runs. The timing will not be exactly every 15 seconds, though, depending on where in the called routine it re-schedules itself.
Use the following site to help generate the proper Quartz Cron string to schedule your job using schedule(), as @bertabcd1234 mentioned.
I believe every 15 seconds would be
0/15 0 0 ? * * *
Hope that helps!
Here's an option
Trigger
VirtualSwitch turns on
Actions to Run
Off: VirtualSwitch
On: VirtualSwitch --> delay 0:00:15
Actions to run...
Thanks all. The actual timing is not critical, just wanted the color change more often. I will play around with the methods suggested today.
I tried the CRON string method. Here is what the generator put out:
schedule("0/15 0 0 ? * * *", colorChange). Problem with that is it didn't want to start until midnight, or first zero second of the day. Not sure why it doesn't start at the first 0 second of the next minute.
So ended up using the runIn. I had thought of that before but wasn't sure you could call it from within the same routine. But my short test showed it worked. I only have this working a few hours in the evening, Christmas Light. So will see what happens this evening but it should be ok.
Thanks again for all the help.
runIn has two problems:
- It is being scheduled every time the routine runs.
- If the routine ever fails, the periodic polling will stop.
Below is my code for a periodic interval that is tried and true. It actually starts within seconds of the code being run. The below was edited to the 10 seconds (from a variable).
schedule("0/10 * * * * ?", onPoll)
The caution on processor loading is still relevant (either way). This way is slightly better but also more reliable.
If it were me, I would look at the logs => Device Stats "% of total" before the mods, make and test the mods, reboot the hub, then look at the stats one hour later. Large Total and % of Total indicate possible issues.
I have some other code that doesn't start the schedule until a certain time. Then it issues the first runIn. Then within the routine it calls I do another runIn at the end of the routine. Thus it should run every 15 seconds until I stop it. And at another time I do an unschedule which should stop it till I start it again.
The whole thing is nothing critical so if it does fail no big deal. The light just won't cycle color. I may or may not notice it right away, but no problem there.
I'll try the cron you have. My ? was in a different place based on that online generator.
Ok, redid the cron based on your string, did a quick test and it started right up. Not sure why the online cron generator was different.
So reset everything and will see if it still works this evening.
Not sure why running a simple routine that just sets color of bulb every 15 seconds should be a processor load issue. That is very minor, insignificant logic programming.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
