Class CleanupEtaUtil

java.lang.Object
org.exoplatform.addons.documents.cleanup.util.CleanupEtaUtil

public class CleanupEtaUtil extends Object
Single definition of the throughput ETA of a cleanup worker, shared by the dry-run scan and the execution purge — the two workers used to carry the very same arithmetic verbatim, so a change (or a regression) in one of them silently diverged from the other.

The estimate is deliberately based on the throughput observed SINCE THIS RUN STARTED, not since the campaign started: a resumed worker must not inherit the throughput of the run that was interrupted (a machine that was slow yesterday says nothing about today's remaining time). It is CUMULATIVE over that run and not windowed — it was once described here as 'rolling', which it never was.

UNIT-AGNOSTIC on purpose: the arithmetic is 'work done over time elapsed', and the caller chooses what a unit of work is. The scan counts NODES, whose cost is near-uniform. The purge counts BYTES (CleanupExecutionService#purgeEtaSeconds), because its items differ in cost by orders of magnitude and a count-based average predicts the items already met rather than the ones left.

  • Method Details

    • computeEtaSeconds

      public static long computeEtaSeconds(long startTime, long processedAtStart, long processed, long total)
      Same as computeEtaSeconds(long, long, long, long, long) evaluated against the current server clock.
      Parameters:
      startTime - epoch millis at which THIS run started
      processedAtStart - work already done when this run started (a resumed worker starts above zero)
      processed - work done so far, including processedAtStart
      total - denominator of the run, in the SAME unit
      Returns:
      estimated remaining seconds, 0 when it cannot be estimated yet
    • computeEtaSeconds

      public static long computeEtaSeconds(long startTime, long processedAtStart, long processed, long total, long nowMillis)
      Remaining time of a run, from the throughput measured since it started. Short-circuits to 0 — 'unknown', never a negative or infinite value — whenever the throughput isn't measurable yet: no time elapsed, or nothing processed since the run started (the very first batch of a resumed worker). A numerator that already reached (or passed) the denominator also yields 0.
      Parameters:
      startTime - epoch millis at which THIS run started
      processedAtStart - items already processed when this run started
      processed - items processed so far, including processedAtStart
      total - denominator of the run
      nowMillis - evaluation time (epoch millis)
      Returns:
      estimated remaining seconds, 0 when it cannot be estimated yet