vica
vica

Reputation: 101

Quartz JDBC Job Store - Maintenance/Cleanup

I am currently in the processes of setting up Quartz in a load balanced environment using the JDBC job store and I am wondering how everyone manages the quartz job store DB.

For me Quartz (2.2.0) will be deployed as a part of a versioned application with multiple versions potentially existing on the one server at the one time. I am using the notation XXScheduler_v1 to ensure multiple schedulers play nice together. My code is working fine, with the quartz tables being populated with the triggers/jobs/etc as appropriate.

One thing I have noticed though is that there seems to be no database cleanup that occurs when the application is undeployed. What I mean is that the Job/Scheduler data seems to stay in the quartz database even though there is no longer a scheduler active.

This is less than ideal and I can imagine with my model the database would get larger than it needed to be with time. Am I missing how to hook-up some clean-up processes? Or does quartz expect us to do the db cleanup manually?

Cheers!

Upvotes: 5

Views: 15323

Answers (4)

dhiraj singh
dhiraj singh

Reputation: 111

I got this issue once, and here is what I did to rectify the issue. This will work for sure but in case it does not then we will have backup of table so you don't have anything to loose while trying this.

  1. Take sql dump of following tables using method mentioned at : Taking backup of single table
    a) QRTZ_CRON_TRIGGERS
    b) QRTZ_SIMPLE_TRIGGERS
    c) QRTZ_TRIGGERS
    d) QRTZ_JOB_DETAILS
  1. Delete data from above tables in sequence as

    delete from QRTZ_CRON_TRIGGERS;
    delete from QRTZ_SIMPLE_TRIGGERS;
    delete from QRTZ_TRIGGERS;
    delete from QRTZ_JOB_DETAILS;
    
  2. Restart your app which will then freshly insert all deleted tasks and related entries in above tables (Provided your app has its logic right).

This is more like starting your app with all the tasks being scheduled for the first time. So you must keep in mind that tasks will behave as if these are freshly inserted.

NOTE: If this does not work then apply the backup you took for tables and try to debug more closely. As of now, I have not seen this method fail.

Upvotes: 7

Krzysztof Tomaszewski
Krzysztof Tomaszewski

Reputation: 1174

To clean Quartz Scheduler internal data one needs more SQL:

delete from QRTZ_CRON_TRIGGERS;
delete from QRTZ_SIMPLE_TRIGGERS;
delete from QRTZ_TRIGGERS;
delete from QRTZ_JOB_DETAILS;
delete from QRTZ_FIRED_TRIGGERS;
delete from QRTZ_LOCKS;
delete from QRTZ_SCHEDULER_STATE;

Upvotes: 0

yair
yair

Reputation: 9255

You're not missing anything.

However, these quartz tables aren't different from any applicative DB objects you use in you data model. You add Employees table and in a later version you don't need it anymore. Who's responsible for deleting the old table? Only you. If you habe a DBA you might roll it on the DBA ;).

This kind of maintenance would typically be done using an uninstall script / wizard, upgrade script / wizard, or during the first startup of the application in its new version.


On a side note, typically different applications use different databases, or different schemas for the least, thus reducing inter-dependencies.

Upvotes: 0

lanimall
lanimall

Reputation: 451

It's definitely not doing any DB cleanup when undeploying the application or shutting down the scheduler. You would have to build some cleanup code during application shutdown (i.e. building some sort of StartupServlet or context listener that would do the cleanup on the destroy() event lifecycle)

Upvotes: 0

Related Questions