If you do not want to add another plugin dependency, the alternative is to use the Timer JDK class. Just add the following to Bootstrap.groovy
def init = { servletContext -> // The code for the task should go inside this closure def task = { println "executing task"} as TimerTask // Figure out when task should execute first def firstExecution = Calendar.instance def hour = firstExecution.get(Calendar.HOUR_OF_DAY) firstExecution.clearTime() firstExecution.set(Calendar.HOUR_OF_DAY, hour + 1) // Calculate interval between executions def oneHourInMs = 1000 * 60 * 60 // Schedule the task new Timer().scheduleAtFixedRate(task, firstExecution.time, oneHourInMs) }
source share