Mornor
Mornor

Reputation: 3783

Jobs in PlayFramework 2.3.X

I need to perform a background task on my PlayFramework 2.3.X server (check DB status and perform action dependind on this status).

To do this, I saw Play used to use Jobs (here) in its early version. I would like to do the same but wasn't able to figure out what is the new way to handle this.

Ps: I know this is not a good thing to do so, but I have to perform this background task. If you find a better way, please feel free to let me know.

Thanks!

EDIT
I try something like this using Java Akka, but I miss a parameter. Any advice?

public static void test(){
        Akka.system().scheduler().schedule (
                Duration.create(0, TimeUnit.MILLISECONDS),   // initial delay 
                Duration.create(5, TimeUnit.MINUTES),        // run job every 5 minutes
                new Runnable() {
                    public void run() {
                        Logger.info("job is done");
                    }
                }; 
         ); 
}

Upvotes: 1

Views: 511

Answers (1)

Michał Wolnicki
Michał Wolnicki

Reputation: 285

Try this:

Runnable task = new Runnable() {

    @Override
    public void run() {
        //your jobs
    }
};


Akka.system().scheduler().schedule(FiniteDuration.create(0, TimeUnit.SECONDS), FiniteDuration.create(1, TimeUnit.SECONDS), task, Akka.system().dispatcher());

Upvotes: 3

Related Questions