scala - How to run a task every day a 11PM

2019-03-03 04:36发布

With playframework, I'm trying to run a function to send a mail every day at 11PM but I don't know how to do. I found many answers accros the internet but I haven't managed to adapt with Scala language, do you have a example of tutorial ?

2条回答
孤傲高冷的网名
2楼-- · 2019-03-03 04:47

Have a look at Akka Scheduler and Play! Scheduled jobs

EDIT:

I'll personally prefer Play! scheduler which uses cron. So in the example (copy/paste), you could create a Scala class similar to this:

import play.jobs.*;

/** Fire at 12pm (noon) every day **/ 
@On("0 0 12 * * ?")
public class Bootstrap extends Job {

    public void doJob() {
        Logger.info("Maintenance job ...");
        ...
    }

}
查看更多
beautiful°
3楼-- · 2019-03-03 04:53

I suggest you to use akka quartz scheduler https://github.com/enragedginger/akka-quartz-scheduler

查看更多
登录 后发表回答