...
and register it with runScheduledJobs()
var myJobs = getMyJobs(minute.toInt, hour.toInt, day_of_week.toInt)
myAction.myActionJob(myJobs)
2b)
create class myAction, ‘ObjectService’ is for example UserService, in that case ‘parameters’ in Jobs MongoDB collection contains user id:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
package models import java.util.Date import services.SchedulerService import services.DI object myAction { val scheduler: SchedulerService = DI.injector.getInstance(classOf[SchedulerService]) val objects: ObjectService = DI.injector.getInstance(classOf[ObjectService]) /** * ‘Do something’ for each job returned by getMyJobs */ def myActionJob(listJob: List[TimerJob]) = { for (job <- listJob){ job.parameters match { case Some(id) => { objects.findById(id) match { case Some(object) => { job.lastJobTime match { case Some(date) => { ‘Do something’ } case None => Logger.debug("LastJobTime not found") } } case None => Logger.debug(“Object not found") } scheduler.updateLastRun(‘jobName’) //sets job’s name for example ”myJob[“ + id + "]") } case None => Logger.debug("Parameters not found") } } } |
...