...
Creating and calling a new timer job
...
Create and update job
A new
TimerJob
job is created and set in the MongoDBCollection
by newly coded functions inapp/services/ScheduleService
andapp/services/mongoldb/MongoDBSchedulerService.scala
called for exampleupdateMyJob():
Code Block language scala def updateMyJob(id: UUID, name: String, setting: String)
and
Code Block language scala def updateMyJob(id: UUID, name: String, setting: String) = { if (jobExists(name) == false) { Jobs.insert(new TimerJob(name, None, None, None, None, Option(‘function’), Option(id), None, Option(new Date()))) } if (setting == "hourly"){ updateJobTime(name, Option(0), None, None, Option(setting)) } else if (setting == "daily"){ updateJobTime(name, Option(0), Option(7), None, Option(setting)) } else if (setting == "weekly"){ updateJobTime(name, Option(0), Option(7), Option(1), Option(setting)) } else { deleteJob(name) } }
This is similar to a function
updateEmailJob
...
()
already implemented in the Clowder whereupdateJobTime(name, Option(0), Option(7), Option(1), Option(setting))
...
refers tot the
...
time
...
set to minute=0, hour=7 and day_of_week=1 (Monday) in the database as mentioned above. When Clowder time matches the values the job is returned from the database and Action is fired.
You can either change
...
time directly in
...
the code or pass the time values from a Play template as additional parameters such as:
Code Block language scala def updateMyJob(id: UUID, name: String, setting: String, minute: Integer)= { updateJobTime(name, Option(minute), None, None, Option(setting)) }
...
from the Play
request
or directly in Scala on the server side call your job update:scheduler.updateMyJob(id, name, setting)
here theid
is a parameters id (parameters: Option[UUID]
, seeTimerJob
model),name
is the job's name andsettings
are used to distinguish time frequency (from options of pull down menus for example - hourly, weekly etc.)
Call and get job
2) get the job (TimerJob) at certain time
2a)
create function getMyJobs in app > models > JobsScheduler.scala
...