コード例 #1
0
ファイル: YouViewUpdater.java プロジェクト: Reedyuk/atlas
  // TODO report status effectively
  @Override
  protected void runTask() {
    try {
      LocalDate today = LocalDate.now(DateTimeZone.UTC);
      LocalDate start = today.minusDays(minusDays);
      LocalDate finish = today.plusDays(plusDays);

      List<Channel> youViewChannels = channelResolver.getAllChannels();

      UpdateProgress progress = UpdateProgress.START;

      while (!start.isAfter(finish)) {
        LocalDate end = start.plusDays(1);
        for (Channel channel : youViewChannels) {
          Interval interval =
              new Interval(start.toDateTimeAtStartOfDay(), end.toDateTimeAtStartOfDay());
          Document xml =
              fetcher.getSchedule(interval.getStart(), interval.getEnd(), getYouViewId(channel));
          Element root = xml.getRootElement();
          Elements entries = root.getChildElements(ENTRY_KEY, root.getNamespaceURI(ATOM_PREFIX));

          progress = progress.reduce(processor.process(channel, entries, interval));
          reportStatus(progress.toString());
        }
        start = end;
      }
    } catch (Exception e) {
      log.error("Exception when processing YouView schedule", e);
      Throwables.propagate(e);
    }
  }
コード例 #2
0
  @Override
  protected void runTask() {

    ContentListingProgress progress = progressStore.progressForTask(scheduleKey);
    log.info("Started: {} from {}", scheduleKey, startProgress(progress));

    Iterator<Content> children =
        contentStore.listContent(
            defaultCriteria()
                .forPublishers(publishers)
                .forContent(ImmutableList.of(CONTAINER))
                .startingAt(progress)
                .build());

    UpdateProgress processed = UpdateProgress.START;
    Content content = null;

    try {
      while (children.hasNext() && shouldContinue()) {
        try {
          content = children.next();
          updateContainerReferences((Container) content);
          reportStatus(String.format("%s. Processing %s", processed, content));
          processed = processed.reduce(SUCCESS);
          if (processed.getTotalProgress() % 100 == 0) {
            updateProgress(progressFrom(content));
          }
        } catch (Exception e) {
          processed = processed.reduce(FAILURE);
          log.error("ChildRef update failed: " + content, e);
        }
      }
    } catch (Exception e) {
      log.error("Exception running task " + scheduleKey, e);
      persistProgress(false, content);
      throw Throwables.propagate(e);
    }
    reportStatus(processed.toString());
    persistProgress(shouldContinue(), content);
  }