Any way to determine if a Scheduled Job is queued?

I have a Groovy app coding situation where the most expedient logic path is to determine if a job with a specific Handler name is scheduled in the Jobs queue, or not.

Is there a method to programmatically get the scheduled jobs queue or test if something is queued for a job name? Obviously something exists since this information is displayed on the App's Status page

Should the answer be no, I can workaround it by setting atomicState variables, however I prefer not doing that.

I don’t believe so. The page you reference there would have direct access to the quartz scheduler API but that’s not exposed via the groovy sandbox.

2 Likes

FWIW, if you just want to make sure that something is not there, calls to unschedule() (for that specific handler, so not without paramaters like I just wrote) appear to be harmless--while expectedly having no effect--if a matching scheduled job doesn't actually exist. I'm not sure what your actual use is for knowing whether something is there, but it sounds like you have a workaround for that if needed. Good luck either way!

It's for a personal lighting control module that works with lux, time, motion sensors, and switches. When lux rises above a set point, and a light is on, the code turns the light off. However, if there is a timed pending Off Job from a prior motion or a switch trigger that set the light On, leave the light on.

One way to make this determination is by scanning the motion or switch device events that caused the event to see if the last active or on event plus the "On Time" has expired, but that's a lot of overhead. Then I realized if there is a queued light off Scheduled Job for the light, leave it On. Hence my need to look at the queue. The workaround is simple, and easy.

My workaround uses atomicState. I know the difference between state and atomicState in SmarttThings, but don't know if it matters or makes any real difference in Hubitat.

unschedule() clears all scheduled jobs
unschedule('name') clears jobs with a matching name

https://docs.hubitat.com/index.php?title=Common_Methods_Object#unschedule