Reputation:
The method Scheduler.getCurrentlyExecutingJobs() in quartz apparently is not cluster aware. What method are people using to get a list of all executing jobs?
Upvotes: 7
Views: 5245
Reputation: 571
Looks like overhauling the scheduling mechanism isn't happening anytime soon.
So, here's how I'm checking the table directly - add group support if you want it:
class QuartzClusterJobStatusService
{
def quartzScheduler
boolean isJobRunning(String job) {
return isJobRunningHere(job) || isJobRunningElsewhere(job)
}
boolean isJobRunningHere(String job) {
for (JobExecutionContext j : quartzScheduler.getCurrentlyExecutingJobs()) {
if (new JobKey(job,"GRAILS_JOBS").equals(j.jobDetail.key)) {
return true
}
}
return false
}
boolean isJobRunningElsewhere(String job) {
JobStoreSupport js = quartzScheduler.sched.resources.jobStore
if (!js.isClustered()) {
return false
}
Connection conn = DBConnectionManager.getInstance().getConnection(js.getDataSource());
PreparedStatement stmt = null
try {
stmt = conn.prepareStatement("SELECT 1 FROM " + js.getTablePrefix() + "FIRED_TRIGGERS where JOB_NAME = ?")
stmt.setString(1, job)
ResultSet rs = stmt.executeQuery()
return rs.next()
} finally {
if (stmt != null)
stmt.close()
}
}
}
Upvotes: 4
Reputation:
I would assume one way is to access the database directly, although its a bit risky since the API completely handles that.
There is an issue in their Jira for this purpose. Their conclusion is you need to overhaul the scheduling mechanism if they want to cater cluster aware.
You can refer to http://jira.opensymphony.com/browse/QUARTZ-372
Upvotes: -1