I am trying to use akka-quartz-scheduler to trigger a cleanup event at regular intervals. I get the scheduler to send the message to the actor, but only when there is no Calendar associated with the schedule. Whenever I attach a calendar to a schedule, the actor never receives any messages.
This is the application.conf section relevant for akka-quartz-scheduler. If I remove the line
calendars = ["Minimal"]"
from the config, my actor is triggered. If I leave the line in, no actor gets called.
akka {
quartz {
defaultTimezone = "Europe/Oslo"
schedules {
NowAndThen {
description ="Delete temp files now and then, eg every hour"
expression = "*/10 * * * * ?"
calendars = ["Minimal"]
}
}
calendars {
Minimal {
type = Daily
exclude {
startTime = "15:00"
endTime = "15:01"
}
}
}
}
}
I am initializing the extension from a playframework application, in Global.java:
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Extension;
import akka.actor.Props;
import com.typesafe.akka.extension.quartz.QuartzSchedulerExtension;
import play.Application;
import play.GlobalSettings;
import play.Logger;
import play.libs.Akka;
import uttrekk.CleanupRunner;
public class Global extends GlobalSettings {
public void onStart(Application app) {
AkkaStartUp.startup(app);
}
static class AkkaStartUp {
public static void startup(Application app) {
// Starter autoamtiske avelveringer norges eiendommer
ActorSystem system = Akka.system();
ActorRef cleanupRef =system.actorOf(new Props(CleanupRunner.class));
QuartzSchedulerExtension scheduler = (QuartzSchedulerExtension) QuartzSchedulerExtension.get(system);
scheduler.schedule("NowAndThen",cleanupRef,"Clean");
}
}
}
The actor implementation looks something like the following:
package uttrekk;
import akka.actor.UntypedActor;
import play.Logger;
import util.NewProperties;
import java.io.File;
import java.io.FilenameFilter;
public class CleanupRunner extends UntypedActor {
@Override
public void onReceive(Object message) throws Exception {
Logger.info("Running cleanup of temporary files");
}
}
the problem occurs during calendars initialization. Check line 245 in QuartzSchedulerExtension class: scheduler.addCalendar(name.toUpperCase, calendar, true, true)
The calendar is added using UpperCase, so Quartz never finds it, producing that no job is triggered then. If you define your calendar in akka config using UpperCase name it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With