Run in every 2 seconds


#3

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.


#4

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


#5

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.


#6

@bangali

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


#7

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

schedule works fine in apps though.


#8

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


#9

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


#10

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?


#11

ok. correct.


#12

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


#13

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


#14

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.


#15

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.


#16

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.


#17

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

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


#18

@chuck.schwer

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


#19

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


#20

@chuck.schwer has this been added somewhere?


#21

Yes, this was added in 1.1.5, you will see it at the bottom of the device details page.


#22

You said this was every 2 seconds forever. So would

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

be every 30 seconds forever? And you cancel it by calling the unschedule(method) function, correct?