Esempio n. 1
0
  @Override
  protected void runTask() {
    DateTime start = new DateTime(DateTimeZones.UTC);
    log.info("C4 EPG Update initiated");

    DayRange dayRange = rangeGenerator.generate(new LocalDate(DateTimeZones.UTC));

    BiMap<String, Channel> channelMap = c4AtomApi.getChannelMap();
    int total = Iterables.size(dayRange) * channelMap.size();
    int processed = 0;
    UpdateProgress progress = UpdateProgress.START;

    for (Map.Entry<String, Channel> channelEntry : channelMap.entrySet()) {
      for (LocalDate scheduleDay : dayRange) {
        reportStatus(progressReport("Processing", processed++, total, progress));
        progress =
            progress.reduce(
                channelDayUpdater.update(
                    channelEntry.getKey(), channelEntry.getValue(), scheduleDay));
      }
    }

    reportStatus(progressReport("Processed", processed++, total, progress));
    String runTime =
        new Period(start, new DateTime(DateTimeZones.UTC)).toString(PeriodFormat.getDefault());
    log.info("C4 EPG Update finished in " + runTime);

    if (progress.hasFailures()) {
      throw new IllegalStateException(
          String.format("Completed with %s failures", progress.getFailures()));
    }
  }
Esempio n. 2
0
  // 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);
    }
  }
Esempio n. 3
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);
  }
Esempio n. 4
0
 private String progressReport(String prefix, int processed, int total, UpdateProgress progress) {
   return String.format(
       "%s %s/%s. %s failures. %s broadcasts processed",
       prefix, processed, total, progress.getFailures(), progress.getProcessed());
 }