I've came to solution using
https://github.com/enragedginger/akka-quartz-scheduler with full support of Guice dependency injection in Play 2.5. See it below:
Module.java:public class Module extends AbstractModule implements AkkaGuiceSupport {
@Override
public void configure() {
// Use the system clock as the default implementation of Clock
bind(Clock.class).toInstance(Clock.systemDefaultZone());
bindActor(SendNotificationActor.class, "send-notification-actor");
bind(Scheduler.class).to(SchedulerImpl.class).asEagerSingleton();
}
}
Scheduler interface:public interface Scheduler {
}
Scheduler implementation class:@Singleton
public class SchedulerImpl implements Scheduler {
/** */
private final ApplicationLifecycle appLifecycle;
/** */
private final ActorSystem actorSystem;
@Inject
public SchedulerImpl(ActorSystem actorSystemInj, ApplicationLifecycle appLifecycleInj, @Named("send-notification-actor") ActorRef sendNotificationActor) {
Logger.debug("Starting SchedulerImpl");
actorSystem = actorSystemInj;
appLifecycle = appLifecycleInj;
QuartzSchedulerExtension scheduler = (QuartzSchedulerExtension) QuartzSchedulerExtension.get(actorSystem);
scheduler.schedule("SendNotification", sendNotificationActor, "");
appLifecycle.addStopHook(() -> {
Logger.debug("Shutting down: SchedulerImpl");
scheduler.shutdown(true);
return CompletableFuture.completedFuture(null);
});
}
}
Actor cron configuration:akka {
threadPool {
threadCount = 3
threadPriority = 5
daemonThreads = true
}
quartz {
schedules {
SendNotification {
description = "Send notification"
expression = "0 * * ? * *"