1

I'm trying to schedule daily Quartz jobs at the same time on certain days of the week, e.g. 9am every Tuesday or 10am on Tuesdays and Wednesdays.

Quartz's firing times are unexpected when the weekday matches the weekday of today's date. Triggers fire at 9am as expected except when today's weekday matches the schedule day, in which case the trigger fires immediately, e.g. if today is Tuesday and the trigger is for Tuesday, instead of firing at 9am next week, the trigger will fire now. Why does Quartz do this?

The only way I have found to prevent this behaviour is to override the trigger's starting time to the following day, but then it misses the trigger for the present day if the current time is before the trigger time, which makes it pointless for me to use Quartz as a daily scheduler.

Note: I am using Quartz via Quartzite, a thin Clojure layer over Quartz, but the unexpected behaviour does not seem to be related to Quartzite.

Here is my trigger-building Clojure code:

(t/build
      (t/with-identity (t/key "some-unique-id"))
      (t/with-schedule (clojurewerkz.quartzite.schedule.daily-interval/schedule
                         (on-days-of-the-week (TreeSet. (vec (map #(Integer/valueOf %) [3 4])))) ; Tuesday and Wednesday
                         (starting-daily-at (daily-interval/time-of-day 09 00 00)))))
walen
  • 7,103
  • 2
  • 37
  • 58
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287

2 Answers2

0

I think this may be a situation you could handle with what quartz calls "misfire handling": http://www.nurkiewicz.com/2012/04/quartz-scheduler-misfire-instructions.html

Imagine if the process went down / died and was down during your scheduled time - you might want it to go ahead and fire when the process comes back up. But it's not clear to me how you'd distinguish between that case (dying process) and the one you describe (where the initial scheduling is for earlier the day the code is... deployed? run for the first time?).

trptcolin
  • 2,320
  • 13
  • 16
0

You can set start-now in which case it'll not consider the trigger if its already passed current time but it'll consider it if it is the same day and time is yet to tick. Since you are not passing start datetime it thinks it misfired for the same day and fires it right away. This should fix your issue.

(t/build
  (t/start-now)
  (t/with-identity (t/key "some-unique-id"))
  (t/with-schedule (clojurewerkz.quartzite.schedule.daily-interval/schedule
                     (on-days-of-the-week (TreeSet. (vec (map #(Integer/valueOf %) [3 4])))) ; Tuesday and Wednesday
                     (starting-daily-at (daily-interval/time-of-day 09 00 00)))))
firesofmay
  • 582
  • 1
  • 3
  • 16