Where is the job support in Play 2.0?

2019-01-11 13:39发布

In Play 1.0, we can define some jobs which will be executed in the background:

@OnApplicatonStart
@Every("1h")
public class DataJob extends Job {
    public void doJob() {
       // ...
    }
}

But I can't find it in Play 2.0. Do I miss something?

3条回答
虎瘦雄心在
2楼-- · 2019-01-11 14:10

For the acutal job part this seems to be the way in Java,

Akka.system().scheduler().schedule(
        Duration.create(0, MILLISECONDS),   // initial delay 
        Duration.create(5, MINUTES),        // run job every 5 minutes

        new Runnable() 
        {
            public void run() 
            {
                ....
            }
        }
    );
查看更多
等我变得足够好
3楼-- · 2019-01-11 14:14

You could use the scheduler service in akka.

http://doc.akka.io/docs/akka/2.0/java/scheduler.html

http://doc.akka.io/docs/akka/2.0/scala/scheduler.html

Basically you create an actor that executes your logic if it receives a certain message.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-11 14:30
登录 后发表回答