Given a Quartz job and the following command
boolean deleted = scheduler.deleteJob(event.getName(), "some group name")
Assuming deleted
comes back as false
, as i understand it, it means that from the stand point of JVM, the job is still there.
With this 2 questions:
If exception is not thrown, is it safe to assume that job was not found? What would cause this? Isn't the only way for this to happen is for the job to be deleted on the first place?
I am using
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.0</version>
</dependency>
Does this strike you as a correct way to handle things? Is my reasoning correct?
boolean deleted;
try {
deleted = scheduler.deleteJob(event.getName(), "some group name");
if (!deleted) {
logger.warn("Quartz failed to delete the job!" + event.getName() + ". Job not found");
}
} catch (SchedulerException e) {
logger.error("There is an internal Scheduler error", e);
}
Deleting a Job and Unscheduling All of Its Triggers // Schedule the job with the trigger scheduler. deleteJob(jobKey("job1", "group1"));
You have to reschedule the job by creating a new trigger. This will replace the same job with a new trigger fire time.
It seems that only way to delete a trigger is to delete the whole job and then re-register the job and trigger.
new JobKey("jobName", "jobGroupName"); As long as your job name and job group name is the same with which you created your job, you will be able to get your job detail.
If you need to delete a job while it's running make sure your job implements org.quartz.InterruptableJob. Then you may call org.quartz.Scheduler.interrupt(JobKey)
to stop it while it's running.
Try adding a catch for general Exception after your SchedulerException (it's better exception handling and if you're not sure about the errors you may get it will help you).
Also keep in mind that when you build the quartz job, you can use jobBuilder.storeDurably(false)
, which will cause your quartz job to be deleted automatically when there are no longer active trigger associated to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With