Grails - Quartz 作业触发器中的参数

发布于 2024-12-04 20:18:29 字数 496 浏览 1 评论 0原文

我有以下石英作业,通过 Quartz 插件设置:

class UserMonthlyNotificationJob { 
static triggers = {
        cron name:'dailyTrigger', cronExpression: " ... "
        cron name:'weeklyTrigger', cronExpression: " ... "
        cron name:'monthlyTrigger', cronExpression: " ... "
}

    def execute(){ ... }
}

我希望能够在触发器中设置一个在 execute 块中可用的参数。 看来我无法在cron触发器中设置任何变量,并且自定义触发器需要实现Quartz Trigger接口,但我不这样做知道该怎么做。

非常感谢任何帮助。

I have the following quartz job, set via Quartz-plugin:

class UserMonthlyNotificationJob { 
static triggers = {
        cron name:'dailyTrigger', cronExpression: " ... "
        cron name:'weeklyTrigger', cronExpression: " ... "
        cron name:'monthlyTrigger', cronExpression: " ... "
}

    def execute(){ ... }
}

I would like to be able to set a parameter in the trigger that would be available in the execute block.
It seems I can not set any variable in a cron trigger, and a custom trigger require to implement the Quartz Trigger interface, which I do not know how to do.

Any help greatly appreciated.

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

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

发布评论

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

评论(2

む无字情书 2024-12-11 20:18:29

让你的作业实现StatefulJob,然后你'将有权访问 JobExecutionContext 具有 触发实例访问器。如果您有自己的 Trigger 类,那将是它的一个实例。

Make your job implement StatefulJob, then you'll have access to JobExecutionContext which has a Trigger instance accessor. If you have your own Trigger class, that will be an instance of it.

半透明的墙 2024-12-11 20:18:29

非常感谢,它成功了。这就是我最终使用它的方式:

import org.quartz.StatefulJob
import org.quartz.JobExecutionContext

class UserPeriodicalNotificationJob implements StatefulJob{   

    static triggers = {
        cron name:'dailyTrigger', cronExpression: ConfigHolder.config.userDailyNotificationJob
        cron name:'weeklyTrigger', cronExpression: ConfigHolder.config.userWeeklyNotificationJob
        cron name:'monthlyTrigger', cronExpression: ConfigHolder.config.userMonthlyNotificationJob   
    }

    void execute(JobExecutionContext context){
        def triggerName = context.trigger.key
        try {
            switch (triggerName) {...}
        }
        catch(Exception) {...}
  }
}

Thank you very much, it did the trick. This is how I ended up using it:

import org.quartz.StatefulJob
import org.quartz.JobExecutionContext

class UserPeriodicalNotificationJob implements StatefulJob{   

    static triggers = {
        cron name:'dailyTrigger', cronExpression: ConfigHolder.config.userDailyNotificationJob
        cron name:'weeklyTrigger', cronExpression: ConfigHolder.config.userWeeklyNotificationJob
        cron name:'monthlyTrigger', cronExpression: ConfigHolder.config.userMonthlyNotificationJob   
    }

    void execute(JobExecutionContext context){
        def triggerName = context.trigger.key
        try {
            switch (triggerName) {...}
        }
        catch(Exception) {...}
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文