0

I am trying to setup a single execution of a job at a specific time in a timezone of a user using Quartz. Now, out of the box, the only way I can tell the scheduler to execute anything in timezone is through cronSchedule. Of coarse, I could, potentially, convert the datetime into a cron expression and then stop that trigger right after first successful execution, but that smells.

Note: Seems like SimpleSchedule does not allow me to set a timezone.

Another option is to convert all the times provided by the user to the timezone of a scheduler, and then create the trigger with that time. But, this is prescription for disaster.

What is my best option here?

Thanks,

Som Bhattacharyya
  • 3,972
  • 35
  • 54
Shurik Agulyansky
  • 2,607
  • 2
  • 34
  • 76

1 Answers1

0

You can update the existing trigger with the required Time Zone and reschedule the job:

http://quartz-scheduler.org/documentation/quartz-2.x/cookbook/UpdateTrigger

  // retrieve the trigger
  Trigger oldTrigger = sched.getTrigger(triggerKey("oldTrigger", "group1");

  // obtain a builder that would produce the trigger
  TriggerBuilder tb = oldTrigger.getTriggerBuilder();

  // update the schedule associated with the builder, and build the new trigger
  // (other builder methods could be called, to change the trigger in any desired way)

  Trigger newTrigger = tb.withSchedule(simpleSchedule()
 .withIntervalInSeconds(10)
 .withRepeatCount(10)
 .inTimeZone(TimeZone.getTimeZone("America/Los_Angeles"))
 .build();

 sched.rescheduleJob(oldTrigger.getKey(), newTrigger);
Dinesh
  • 160
  • 1
  • 2
  • 13