Hi everyone,
We are running the application in core java with quartz job scheduler(add/update/delete jobs).
Now we are moving it to play framework(with akka distribution), so i want the help regarding the integration of QUARTZ job scheduler in play framework.
I gone through the play and akka docs but didn't get how to implement it.
We want quartz job scheduler with add/update/delete jobs functionality.
Please help us ASAP.
Thanks
Raju
// Global.scala
val scheduler = StdSchedulerFactory.getDefaultScheduler()
override def onStart(app: Application) {
scheduler.start()
val job = newJob(classOf[MyWorker]).withIdentity("job1", "group1").build();
val trigger = newTrigger()
.withIdentity("myWorker", "group1")
.withSchedule(dailyAtHourAndMinute(0, 0))
.forJob(job)
.build()
scheduler.scheduleJob(job, trigger)
}
override def onStop(app: Application) {
scheduler.shutdown()
}
class MyWorker extends Job {
def execute(ctxt: JobExecutionContext) {
Logger.debug("Do what you are there for!")
}
}--
--
def registerDailyJob(job: () => Unit, hour:Int, minute:Int) {
val minMs = 60 * 1000
val hourMs = minMs * 60
val dayMs = hourMs * 24
val initialDelayMs = getNextInitialDelayMs(Calendar.getInstance(), hour, minute)
Logger.debug("registerDailyJob " + initialDelayMs + ", " + dayMs)
Akka.system.scheduler.schedule(initialDelayMs milliseconds, dayMs milliseconds) {
job()
}
}
def getNextInitialDelayMs(from:Calendar, hour:Int, minute:Int):Long = {
var next:Calendar = from.clone().asInstanceOf[Calendar]
next.set(Calendar.HOUR_OF_DAY, hour)
next.set(Calendar.MINUTE, minute)
if (next.compareTo(from) < 0)
next.add(Calendar.DATE, 1)
next.getTimeInMillis - from.getTimeInMillis
}