Versions Compared

Key

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

...



2c)
implement ‘Do something’ in myAction (see 2b)




Note that ‘day_of_month’ is part of the TimerJob model but it is not implemented in scheduler.getJobByTime
Adding it is straightforward:
1) in app > services > SchedulerService.scala add day_of_month (or day)
2) in app > services > mongoldb > MongoDBSchedulerService.scala

2a) update

Code Block
languagescala
def getJobByTime(minute: Integer, hour: Integer, day_of_week: Integer, day: Integer): List[TimerJob] ={

...


    val jobs = Jobs.find(

...


      $and(
        // either day exists AND the value is 'day' OR day does not exist
        $or($and("day" $exists true, MongoDBObject("day" ->

...

 day)),

...


        // either day_of_week exists AND the value is 'day' OR day_of_week does not

...

 exist
        $or($and("day_of_week" $exists true, MongoDBObject("day_of_week" ->

...

 day_of_week)), "day_of_week" $exists false),

...


        // either hour exists AND the value is 'hour' OR hour does not

...

 exist
        $or($and("hour" $exists true, MongoDBObject("hour" ->

...

 hour)), "hour" $exists false),

...


        // either minute exists AND the value is 'minute' OR minute does not

...

 exist
        $or($and("minute" $exists true, MongoDBObject("minute" ->

...

 minute)), "minute" $exists false)

...


      )
    )


2b) update

Code Block
languagescala
collapsetrue
def updateJobTime(name: String, minute: Option[Integer], hour: Option[Integer], day_of_week: Option[Integer], day: Option[Integer], freq: Option[String]) = {
    if (minute == None){
      Jobs.dao.update(MongoDBObject("name" -> name), $unset("minute"))
    }
    else {
      Jobs.dao.update(MongoDBObject("name" -> name), $set("minute" -> minute))
    }

    if (hour == None){
      Jobs.dao.update(MongoDBObject("name" -> name), $unset("hour"))
    }
    else {
      Jobs.dao.update(MongoDBObject("name" -> name), $set("hour" -> hour))
    }

    if (day_of_week == None){
      Jobs.dao.update(MongoDBObject("name" -> name), $unset("day_of_week"))
    }
    else {
      Jobs.dao.update(MongoDBObject("name" -> name), $set("day_of_week" -> day_of_week))
    }

    if (day == None){
      Jobs.dao.update(MongoDBObject("name" -> name), $unset("day"))
    }
    else {
      Jobs.dao.update(MongoDBObject("name" -> name), $set("day" -> day))
    }

    Jobs.dao.update(MongoDBObject("name" -> name), $set("frequency" -> freq))
  }

...