为了从GUI中设置一个警报,我想将一个变量作为参数传递给cron。
这样做是可行的:
rule "Wake up"
when
Time cron "00 00 06 * * ?"
then
// ...
end这样做是行不通的:
var morning = "00 00 06 * * ?"
rule "Wake up"
when
Time cron morning
then
// ...
end这应该是可能的吗?
发布于 2022-04-07 01:03:53
无法更改Cron字符串,但我使用这段代码来绕过它:
import org.joda.time.Duration
import org.quartz.CronExpression
var Timer wateringtimer = null
// Start watering at 03:00 AM, all days except Saturday (5)
val wateringCronString = "0 0 3 ? * 1,2,3,4,5,6"
...
rule "Set Cron"
...
var cronExpression = new CronExpression(wateringCronString)
var triggerTime = cronExpression.getNextValidTimeAfter(now.plusMinutes(1).toDate)
Seconds::secondsBetween(now,new DateTime(triggerTime)).getSeconds()
if (watertimer !== null)
watertimer.cancel()
wateringtimer = createTimer(now.plusSeconds(diff),
[
...Do something...
])https://stackoverflow.com/questions/33836291
复制相似问题