@Override
 public Query<PostEntity> posts() {
   QueryBuilder<PostEntity> queryBuilder = module.newQueryBuilder(PostEntity.class);
   return module
       .currentUnitOfWork()
       .newQuery(queryBuilder)
       .orderBy(templateFor(PostEntity.class).postedAt(), Order.DESCENDING);
 }
Exemplo n.º 2
0
 @Override
 public Schedule scheduleOnce(Task task, DateTime runAt, boolean durable) {
   Schedule schedule = scheduleFactory.newOnceSchedule(task, runAt, durable);
   dispatchForExecution(schedule);
   if (durable) {
     Schedules schedules =
         module.currentUnitOfWork().get(Schedules.class, getSchedulesIdentity(me));
     schedules.schedules().add(schedule);
   }
   return schedule;
 }
Exemplo n.º 3
0
 @Override
 public Schedule scheduleCron(
     Task task, @CronExpression String cronExpression, DateTime start, boolean durable) {
   Schedule schedule = scheduleFactory.newCronSchedule(task, cronExpression, start, durable);
   if (durable) {
     Schedules schedules =
         module.currentUnitOfWork().get(Schedules.class, getSchedulesIdentity(me));
     schedules.schedules().add(schedule);
   }
   dispatchForExecution(schedule);
   return schedule;
 }
 @Override
 public Iterable<TimelineRecord> getNextRecords(int maxResults) {
   SortedSet<TimelineRecord> result = new TreeSet<>();
   UnitOfWork uow = module.currentUnitOfWork();
   String schedulesName = SchedulerMixin.getSchedulesIdentity(scheduler);
   Schedules schedules = uow.get(Schedules.class, schedulesName);
   for (Schedule schedule : schedules.schedules()) {
     Timeline timeline = (Timeline) schedule;
     Iterable<TimelineRecord> lastRecords = timeline.getNextRecords(maxResults);
     Iterables.addAll(result, lastRecords);
   }
   return Iterables.limit(maxResults, result);
 }
Exemplo n.º 5
0
 @Override
 public Schedule scheduleCron(
     Task task, String cronExpression, long initialDelay, boolean durable) {
   DateTime start = new DateTime(System.currentTimeMillis() + initialDelay);
   Schedule schedule = scheduleFactory.newCronSchedule(task, cronExpression, start, durable);
   if (durable) {
     Schedules schedules =
         module.currentUnitOfWork().get(Schedules.class, getSchedulesIdentity(me));
     schedules.schedules().add(schedule);
   }
   dispatchForExecution(schedule);
   return schedule;
 }
  @Override
  public Iterable<TimelineRecord> getRecords(DateTime from, DateTime to) {
    SortedSet<TimelineRecord> result = new TreeSet<>();

    UnitOfWork uow = module.currentUnitOfWork();
    String schedulesName = SchedulerMixin.getSchedulesIdentity(scheduler);
    Schedules schedules = uow.get(Schedules.class, schedulesName);
    for (Schedule schedule : schedules.schedules()) {
      Timeline timeline = (Timeline) schedule;
      Iterable<TimelineRecord> lastRecords = timeline.getRecords(from, to);
      Iterables.addAll(result, lastRecords);
    }
    return result;
  }
Exemplo n.º 7
0
 @Override
 public Schedule scheduleOnce(Task task, int initialSecondsDelay, boolean durable) {
   long now = System.currentTimeMillis();
   Schedule schedule =
       scheduleFactory.newOnceSchedule(
           task, new DateTime(now + initialSecondsDelay * 1000), durable);
   if (durable) {
     Schedules schedules =
         module.currentUnitOfWork().get(Schedules.class, getSchedulesIdentity(me));
     schedules.schedules().add(schedule);
   }
   dispatchForExecution(schedule);
   return schedule;
 }
 @Override
 public PostEntity postByIdentity(String identity) throws NoSuchEntityException {
   return module.currentUnitOfWork().get(PostEntity.class, identity);
 }