Run in every 2 seconds

i have this method that runs every 2 secs for roughly 20 milliseconds. it seems to run ok for a while then stops running without any errors.

is there any protection in place like for hung or runaway methods that would terminate the schedule for this method after a while?

thank you.

here is example code:

...

updated() {
   runEvery2Seconds()
}

...

runEvery2Seconds() {
   do something
   runIn(2, runEvery2Seconds)
}

Not answering direct question, however, runIn is not a reliable method for scheduling periodic tasks. If the method that calls the next run-in fails for any reason, then the periodic stream will cease. You could improve reality by placing the next runIn call prior to the do something.

sure. thank you. :slight_smile:

though in this case the code is a few lines, likelihood of failing is pretty low and no error in the logs.

You should try schedule() and give it a cron string.

1 Like

will do ... does schedule work in drivers?

think i had tried this first ... which didnt seem to work.

schedule("0/2 0 0 ? * * *", method)

thank you.

@bangali

I need to do something similar. Did you ever make this work?

i still use runIn in the driver … havent checked if schedule works now.

schedule works fine in apps though.

1 Like

Yes, schedule works fine in drivers. assuming you create your cron schedule correctly :wink:

For the above example,, it will run every 2 seconds from 12:00am to 12:01 am

0/2 0 0 ? * * *
XXX                  Every 2 seconds
    X                during minute zero
      X              during hour zero
        X            any day of the month
          X          every month
            X        every day of the week
              X      every year

Run every 2 seconds forever:

schedule("0/2 * * * * ? *", method)

http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html

3 Likes

was that fixed after may 27th? because as of may 27th the day i posted the above … schedule wasnt scheduling anything from a driver.

No, there were no changes to that method since launch. As I mentioned, the cron expression you had only ran for 1 minute at midnight,, is that what you were expecting?

ok. correct.

I tried after this post. I did not seem to get any effect at all from it.

You tried what? can you post the schedule command you tried?

After looking at your example closer my cron string was off. I used a website to generate it for me. I just tried again. My job seems to be happily firing right on time.

1 Like

Great! The thing to keep in mind is that a standard cron expression only goes as low as minutes, ours has seconds as well so there is an extra parameter at the beginning. The quartz reference I posted above is the correct one.

2 Likes

inserted this code, saved then saved the app settings:

schedule("0/2 * * * * ? *", method)

def method()	{
    log.debug "this worked"
}

dang it i copied the cron you provided. let me try the original to make sure it works right.

EDIT: yeah the original schedules fine:

o well … at least its working right now. :slight_smile:

thanks.

btw … heres the website i use for cron generator for quartz:

https://freeformatter.com/cron-expression-generator-quartz.html

2 Likes

@chuck.schwer

Is there anywhere that we can see the upcoming scheduled events for drivers like we can for apps?

No there is not, but I just put in a ticket to add it! :slight_smile:

2 Likes

@chuck.schwer has this been added somewhere?