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

后端 未结 2 726
有刺的猬
有刺的猬 2021-01-25 17:02

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 t

2条回答
  •  滥情空心
    2021-01-25 17:41

    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 ...");
            ...
        }
    
    }
    

提交回复
热议问题