Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Creating and calling a new timer job

...

Create and update job

  1. A new TimerJob job is created and set in the MongoDB Collection by newly coded functions in app/services/ScheduleService and app/services/mongoldb/MongoDBSchedulerService.scala called for example  updateMyJob():

    Code Block
    languagescala
    def updateMyJob(id: UUID, name: String, setting: String)

    and

    Code Block
    languagescala
    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

...

  1. () already implemented in the Clowder where  updateJobTime(name, Option(0), Option(7), Option(1), Option(setting))

...

  1. refers tot the

...

  1. time

...

  1. 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

...

  1. time directly in

...

  1. the code or pass the time values from a Play template as additional parameters such as:

    Code Block
    languagescala
    def updateMyJob(id: UUID, name: String, setting: String, minute: Integer)= {
        updateJobTime(name, Option(minute), None, None, Option(setting))
    }

...

  1. from the Play request or directly in Scala on the server side call your job update:
    scheduler.updateMyJob(id, name, setting)
    here the id is a parameters id (parameters: Option[UUID], see TimerJob model), name is the job's name and settings 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

...