Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove unused triggers from quartz tables

I'm using spring with Quartz and every thing is working fine but some previously cofigured triggers also got executed because they are stored in Quartz tables. Manually we can delete all unconfigured triggers and execute the application but that is not a good practice. I want to remove all the triggers through a spring+quartz property or some other solution.

When I have configured 3 triggers in spring configuration file like

<property name="triggers">
    <list>
        <ref bean="FirstTrigger" />
        <ref bean="secondTrigger" />
        <ref bean="ThirdTrigger"/>
    </list>
</property>

When server started, all the triggers stored in Quartz tables with corresponding cron triggers and job details. If i remove any of the triggers in my configuration, in above for example I removed second Trigger, but it wasn't removed from Quartz tables. At that time DBtrigger (removed trigger) also executed.

In spring + Quartz integration, is there any property to handle this problem or do we need to do something else for this problem?

Thanks in advance.

like image 900
satya Avatar asked Feb 07 '13 10:02

satya


People also ask

How do I Unschedule a quartz job?

We can unschedule a Job by calling the unschedule() method of the Scheduler class and passing the TriggerKey . If the related job does not have any other triggers, and the job is not durable, then the job will also be deleted.

What is trigger in quartz?

Trigger - a component that defines the schedule upon which a given Job will be executed. JobBuilder - used to define/build JobDetail instances, which define instances of Jobs.

How do you stop a spring Quartz scheduler?

deleteJob(jobKey(<JobKey>, <JobGroup>)); This method will only interrupt/stop the job uniquely identified by the Job Key and Group within the scheduler which may have many other jobs running. scheduler. shutdown();


1 Answers

If you store triggers in DB (suppose your triggers are cron-based), you can simply delete records like this:

DELETE FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME='scheduler' and TRIGGER_NAME='myTrigger' and TRIGGER_GROUP='DEFAULT';
DELETE FROM QRTZ_TRIGGERS WHERE SCHED_NAME='scheduler' and TRIGGER_NAME='myTrigger' and TRIGGER_GROUP='DEFAULT';

You may also consider looking around other Quartz DB tables to find leftovers related to your job.

like image 140
snowindy Avatar answered Oct 04 '22 23:10

snowindy