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

后端 未结 2 720
有刺的猬
有刺的猬 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 ...");
            ...
        }
    
    }
    
    0 讨论(0)
  • 2021-01-25 17:48

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

    0 讨论(0)
提交回复
热议问题