Where is the job support in Play 2.0?
Asked Answered
P

3

16

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?

Petrina answered 18/2, 2012 at 8:16 Comment(3)
@Peter Mortensen, thanks for fixing the mistakes of my question.Petrina
Hy @Petrina have you got solution? if yes, please do tell me know as well.Kaule
@MuneebNasir See the answer https://mcmap.net/q/736567/-where-is-the-job-support-in-play-2-0Petrina
P
1

Fixed the links in original accepted answer which posted by JonasAnso

To obtain the functionality of OnApplicationStart you can use Global onStart

Here you can schedule your actors using Akka.

Hope it helps.

Petrina answered 6/10, 2015 at 14:40 Comment(1)
It seems from Play 2.4, GlobalSettings is deprecated? What's the new solution?Formation
C
6

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.

Capable answered 18/2, 2012 at 17:28 Comment(2)
I think this is not I'm looking for. The jobs don't need to be triggered by actions, they are just working in the background.Petrina
For example, how to use akka's scheduler to implement @OnApplicatonStart?Petrina
T
6

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() 
            {
                ....
            }
        }
    );
These answered 1/10, 2012 at 7:30 Comment(1)
See playframework.com/documentation/2.3.x/ScalaAkka for more details.Flawy
P
1

Fixed the links in original accepted answer which posted by JonasAnso

To obtain the functionality of OnApplicationStart you can use Global onStart

Here you can schedule your actors using Akka.

Hope it helps.

Petrina answered 6/10, 2015 at 14:40 Comment(1)
It seems from Play 2.4, GlobalSettings is deprecated? What's the new solution?Formation

© 2022 - 2024 — McMap. All rights reserved.