Search in sources :

Example 1 with CronTrigger

use of fr.wseduc.cron.CronTrigger in project statistics by OPEN-ENT-NG.

the class Statistics method start.

@Override
public void start() {
    super.start();
    JsonArray accessModules = container.config().getArray("access-modules", null);
    if (accessModules == null || accessModules.size() == 0) {
        log.error("Parameter access-modules is null or empty");
        return;
    }
    // 1) Schedule daily aggregation
    /* By default, fire aggregate-cron at 1:15am every day.
		 * Be careful when setting fire times between midnight and 1:00 AM
		 * - "daylight savings" can cause a skip or a repeat depending on whether the time moves back or jumps forward.
		 */
    final String aggregateEventsCron = container.config().getString("aggregate-cron", "0 15 1 ? * * *");
    AggregateTask aggTask = new AggregateTask();
    try {
        new CronTrigger(vertx, aggregateEventsCron).schedule(aggTask);
    } catch (ParseException e) {
        log.fatal(e.getMessage(), e);
        return;
    }
    // In development environment, launch aggregations if parameter "aggregateOnStart" is set to true in module configuration
    if ("dev".equals(container.config().getString("mode", null)) && container.config().getBoolean("aggregateOnStart", false)) {
        Date startDate = new Date();
        // Thu, 30 Apr 2015 00:00:00 GMT
        startDate.setTime(1430352000000L);
        Date endDate = new Date();
        // Fri, 01 May 2015 00:00:00 GMT
        endDate.setTime(1430438400000L);
        this.aggregateEvents(vertx, startDate, endDate);
    }
    // 2) Init controller
    addController(new StatisticsController(vertx, MongoConstants.COLLECTIONS.stats.toString(), accessModules));
    MongoDbConf.getInstance().setCollection(MongoConstants.COLLECTIONS.stats.toString());
// FIXME : the statistics will be kept one year to antoher. No repositoryEvents management
}
Also used : JsonArray(org.vertx.java.core.json.JsonArray) AggregateTask(net.atos.entng.statistics.aggregation.AggregateTask) CronTrigger(fr.wseduc.cron.CronTrigger) StatisticsController(net.atos.entng.statistics.controllers.StatisticsController) ParseException(java.text.ParseException) Date(java.util.Date)

Aggregations

CronTrigger (fr.wseduc.cron.CronTrigger)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 AggregateTask (net.atos.entng.statistics.aggregation.AggregateTask)1 StatisticsController (net.atos.entng.statistics.controllers.StatisticsController)1 JsonArray (org.vertx.java.core.json.JsonArray)1