Esempio n. 1
0
 // WARN Watch this code, see if we can do better, maybe leverage @UnitOfWorkRetry
 @Override
 public void run() {
   System.out.println("Running Schedule");
   Usecase usecase = UsecaseBuilder.newUsecase("ScheduleRunner");
   UnitOfWork uow = module.newUnitOfWork(usecase);
   try {
     Schedule schedule = uow.get(Schedule.class, this.schedule.scheduleIdentity);
     Task task = schedule.task().get();
     schedule = uow.get(Schedule.class, this.schedule.scheduleIdentity);
     try {
       schedule.taskStarting();
       task.run();
       schedule.taskCompletedSuccessfully();
     } catch (RuntimeException ex) {
       schedule.taskCompletedWithException(ex);
     }
     schedulerMixin.dispatchForExecution(schedule);
     uow.complete();
   } catch (UnitOfWorkCompletionException ex) {
   } finally {
     // What should we do if we can't manage the Running flag??
     if (uow.isOpen()) {
       uow.discard();
     }
   }
 }
Esempio n. 2
0
 private void loadSchedules() throws UnitOfWorkCompletionException {
   UnitOfWork uow = module.newUnitOfWork();
   try {
     Schedules schedules = uow.get(Schedules.class, getSchedulesIdentity(me));
     for (Schedule schedule : schedules.schedules()) {
       dispatchForExecution(schedule);
     }
   } catch (NoSuchEntityException e) {
     // Create a new Schedules entity for keeping track of them all.
     uow.newEntity(Schedules.class, getSchedulesIdentity(me));
     uow.complete();
   } finally {
     if (uow.isOpen()) {
       uow.discard();
     }
   }
 }