Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz fails to delete a job, now what?

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:

  1. Is it possible to force delete a job?
  2. What event prevents Quartz to delete a job?

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);
    }
like image 703
James Raitsev Avatar asked Apr 23 '13 15:04

James Raitsev


People also ask

How do you delete a job in quartz scheduler?

Deleting a Job and Unscheduling All of Its Triggers // Schedule the job with the trigger scheduler. deleteJob(jobKey("job1", "group1"));

How do you reschedule a quartz job?

You have to reschedule the job by creating a new trigger. This will replace the same job with a new trigger fire time.

How do I delete a quartz trigger?

It seems that only way to delete a trigger is to delete the whole job and then re-register the job and trigger.

How do I get job details in quartz?

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.


1 Answers

  1. Yes, you're already doing it.
  2. The job is currently running.

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.

like image 174
Nick Patsaris Avatar answered Oct 18 '22 22:10

Nick Patsaris