gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:08:18 26 4
gpt4 key购买 nike

我正在使用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中对此进行了测试,并且可以确认我问题中的两种方法现在都可以使用。

关于grails - 如何使用Grails Quartz2插件在指定时间设置一次性工作触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14498162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com