Grails - Quartz 作业触发器中的参数
我有以下石英作业,通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让你的作业实现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.
非常感谢,它成功了。这就是我最终使用它的方式:
Thank you very much, it did the trick. This is how I ended up using it: