使用 Quartz 获取集群中当前正在执行的所有作业的列表

发布于 2024-07-25 07:00:07 字数 91 浏览 5 评论 0原文

quartz 中的 Scheduler.getCurrentlyExecutingJobs() 方法显然不支持集群。 人们使用什么方法来获取所有正在执行的作业的列表?

The method Scheduler.getCurrentlyExecutingJobs() in quartz apparently is not cluster aware. What method are people using to get a list of all executing jobs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2024-08-01 07:00:07

看起来调度机制的彻底改革不会很快发生。

因此,以下是我直接检查表格的方法 - 如果需要,可以添加组支持:

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()
        }
    }
}

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()
        }
    }
}
深陷 2024-08-01 07:00:07

我假设一种方法是直接访问数据库,尽管它有点冒险,因为 API 完全处理了这个问题。

为此,他们的 Jira 中存在一个问题。 他们的结论是,如果他们想要满足集群感知的需求,则需要彻底改革调度机制。

您可以参考http://jira.opensymphony.com/browse/QUARTZ-372

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文