This is a simple Play 2.6 module, which allows you to manage jobs.
You will need to add the following resolver in your build.sbt
file:
resolvers += "tuxburner.github.io" at "http://tuxburner.github.io/repo"
Add a dependency on the following artifact:
libraryDependencies += "com.github.tuxBurner" %% "play-akkajobs" % "2.6.0"
Activate the module in the conf/application.conf
like this:
play.modules.enabled += "com.github.tuxBurner.jobs.JobModule"
To enable logging or change the level you can configure the logger in your conf/logback.xml
<logger name="com.github.tuxBurner.jobs.JobModule" level="Debug" />
You can implement your own job class with extending it with: com.github.tuxBurner.jobs.AbstractAkkaJob
or you can use one of the implementations which are already there.
The cron expressions you can use are documented under: http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html
Just create a class like this and you will have a job which is called every 15 seconds.
package com.github.tuxBurner.jobs;
import akka.actor.ActorSystem;
import play.Logger;
/**
* Simple job which is fired every 15 Seconds
*/
@AkkaJob(cronExpression = "0/15 * * * * ?")
public class TestAnnotatedJob extends AbstractAnnotatedJob{
public TestJob(ActorSystem actorSystem) throws JobException {
super(actorSystem);
}
@Override
public void runInternal() {
Logger.debug("Run run");
}
}
Just create a class like this.
package com.github.tuxBurner.jobs;
import akka.actor.ActorSystem;
import play.Logger;
/**
* Simple job which is configured via configuration
*/
public class TestConfiguredJob extends AbstractConfigurationJob{
public TestConfiguredJob(ActorSystem actorSystem) throws JobException {
super(actorSystem);
}
@Override
public void runInternal() {
Logger.debug("Run run");
}
}
Now you have to add a jobs section in application.conf file
jobs {
com.github.tuxBurner.jobs.TestConfiguredJob {
enabled = true
cronExpression = "0 0 0/1 * * ?"
key1 = "test1"
key2 = "test1"
}
}
To access key1 for example in your job runInternal you can do the following:
final String key1 = getConfiguration().getString("key1");