使用自定义触发器和参数安排作业
我正在使用 Grails Quartz 插件,并希望使用以编程方式创建的触发器来安排我的作业。我事先不知道执行间隔是多少。我希望这项工作无限期地执行。
==动态作业调度==
从 0.4.1 版本开始,您可以动态安排作业执行。
这些方法可用:
MyJob.schedule(String cronExpression, Map params?)
创建 cron 触发器;MyJob.schedule(LongrepeatInterval, IntegerrepeatCount?, Map params?)
创建简单触发器:重复作业repeatCount+1次,延迟repeatInterval毫秒;MyJob.schedule(Date ScheduleDate, Map params?)
将一项作业安排到特定日期执行;MyJob.schedule(Trigger trigger)
使用自定义触发器安排作业的执行;
MyJob.triggerNow(Map params?)
强制立即执行作业。每个方法(自定义触发器除外)都采用可选的“params”参数。您可以使用它将一些数据传递到您的作业,然后从作业中访问它。
Grails 版本 1.3.7 Quartz 插件版本 0.4.2
那么,为什么 MyJob.schedule(Trigger trigger)
不接受参数?而且,如何使用自定义触发器和作业的映射或参数来实现我想要的目标?
I am using the Grails Quartz plugin and want to schedule my jobs with a programmatically-created Trigger. I do not know beforehand what the execution interval will be. I want the job to execute indefinitely.
The docs give some examples of how to schedule/trigger jobs:
== Dynamic Jobs Scheduling ==
Starting from 0.4.1 version you have the ability to schedule job executions dynamically.
These methods are available:
MyJob.schedule(String cronExpression, Map params?)
creates cron trigger;MyJob.schedule(Long repeatInterval, Integer repeatCount?, Map params?)
creates simple trigger: repeats job repeatCount+1 times with delay of repeatInterval milliseconds;MyJob.schedule(Date scheduleDate, Map params?)
schedules one job execution to the specific date;MyJob.schedule(Trigger trigger)
schedules job's execution with a custom trigger;
MyJob.triggerNow(Map params?)
force immediate execution of the job.Each method (except the one for custom trigger) takes optional 'params' argument. You can use it to pass some data to your job and then access it from the job.
Grails Version 1.3.7
Quartz Plugin version 0.4.2
So, why does the MyJob.schedule(Trigger trigger)
not take params? And, how can I achieve what I want, using a custom trigger and a map or params for the Job?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看 这些方法的定义位置 a href="https://github.com/nebolsin/grails-quartz" rel="nofollow">Quartz插件源码,可以看到所有需要的函数
Map params
是创建触发器
的包装器,然后将其触发到调度程序。MyJob.schedule(Trigger trigger)
方法只是触发您传递给它的触发器,因此您需要在之前将参数添加到 TriggersjobDataMap
属性中调用这个方法,即:If you look where these methods are defined in the Quartz plugin sourcecode, you can see that all of the functions that take
Map params
are wrappers which create aTrigger
and then fire it off to the scheduler.The
MyJob.schedule(Trigger trigger)
method, just fires off the trigger you pass it, so it is up to you to add your params into the TriggersjobDataMap
property before you call this method, ie:蒂姆的回答是正确的,这里有一点更新。
tim answer is correct, here is little bit updation.