9

How to define every five minutes to run jobs

in the play.jobs.every class ,it define an example every("1h") to run job every hour,bu i want to run every 5 minutes,how to define this.

i try the every("5m") or every("0.1h") ,play reports internal error.

Lion
  • 271
  • 5
  • 10

2 Answers2

18

Short answer:

You can use either of the following

@Every("5mn")
@Every("5min")


Long answer:

The @Every annotation uses the play.libs.Time class, and specifically the parseDuration method to determine how often the job is scheduled.

If you look at the source code, the Javadoc states...

   /**
     * Parse a duration
     * @param duration 3h, 2mn, 7s
     * @return The number of seconds
     */

This would suggest that you should specify your code as @Every("5mn")

If you look deeper into the code, it determines that the time is in minutes by using the following regular expression.

"^([0-9]+)mi?n$"

So, this states that either of the following are valid

@Every("5mn")
@Every("5min")
ripper234
  • 222,824
  • 274
  • 634
  • 905
Codemwnci
  • 54,176
  • 10
  • 96
  • 129
5

Try using "5min" in your annotation instead:

@Every("5min")
dogbane
  • 266,786
  • 75
  • 396
  • 414