繁体   English   中英

如何使用Grails Quartz2插件在指定时间设置一次性工作触发器

[英]How to set up a one-off job trigger at a specified time using Grails Quartz2 plugin

我正在使用Quartz2 Plugin ,并试图动态触发一个非常简单的工作。 当用户执行某项操作时,该作业应在将来某个特定的分钟数内触发,并且只能运行一次。

我尝试使用简单的“计划”方法来获取日期和工作数据:

def sendTime = new Date()
use(groovy.time.TimeCategory) {
    sendTime = sendTime + (connectionInstance.timeout).minutes
    println "I will send the job at $sendTime"
}
ReportSmssyncTimeoutJob.schedule(sendTime, [connectionId:params.id])

在这种设置中,我发现作业实际上立即触发,而不是等到“ sendTime”。

在查看插件源代码之后,我的第二次尝试是使用SimpleTrigger

def sendTime = new Date()
use(groovy.time.TimeCategory) {
    sendTime = sendTime + (connectionInstance.timeout).minutes
    println "I will send the job at $sendTime"
}
// arguments here are: jobKey='test', startTime=sendTime, repeatCount=0, repeatInterval=1 (zero not allowed), job-arguments)
def trigger = TriggerHelper.simpleTrigger(new JobKey("test"), sendTime, 0, 1, [connectionId:params.id])
ReportSmssyncTimeoutJob.schedule(trigger)

在此设置中,作业也会立即触发。 SimpleTrigger实现有什么问题,它可以阻止它等到startDate为止?

不幸的是,切换到主要的“ quartz”插件(现在已支持Quartz 2)是不可行的,因为我正在从事一个项目,该项目设置了许多工作以与quartz2插件一起使用。

我在Grails邮件列表中询问了此问题,并得到了答案:这是quartz2插件中的错误。 它应该在下一个版本中修复(错误已在0.2.3中指出)。

更新:在quartz2插件的v2.1.6.2中对此进行了测试,并且可以确认我问题中的两种方法现在都可以使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM