Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka-quartz scheduler never triggers my actor

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");
  }
}
like image 468
Leif Jantzen Avatar asked Nov 01 '13 13:11

Leif Jantzen


1 Answers

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.

like image 151
Patricio Gorin Avatar answered Nov 15 '22 07:11

Patricio Gorin