Class Polling

java.lang.Object
com.qtsurfer.api.sdk.internal.Polling

public final class Polling extends Object
The single polling loop every workflow stage runs on, on top of Policies.stagePoller(java.time.Duration, java.time.Duration, java.time.Duration, java.util.function.Predicate<T>): interrupt handling, the per-attempt callback, and the mapping from Failsafe's failures onto the SDK error hierarchy.

Deliberately knows nothing about the generated models — a stage supplies its own fetch, its own "keep going" predicate and its own per-attempt callback, so adding a stage never widens this class.

  • Method Details

    • poll

      public static <T> T poll(String stage, Duration pollInterval, Duration maxPollInterval, Duration timeout, Supplier<T> fetch, Predicate<T> retryWhile, Consumer<T> onResult)
      Poll fetch until retryWhile stops matching, then return the last result.
      Type Parameters:
      T - polled state type
      Parameters:
      stage - label used in the timeout message, e.g. PREPARING
      pollInterval - initial interval between attempts
      maxPollInterval - upper bound of the exponential backoff
      timeout - overall deadline for this stage; null disables
      fetch - reads the current state
      retryWhile - true while the state is not terminal
      onResult - called with every attempt's result, terminal or not; may be null
      Returns:
      the first result retryWhile rejected
      Throws:
      QTSTimeoutError - when the stage outlives timeout
      QTSCanceledError - when the polling thread is interrupted
      QTSError - when fetch fails; the original error is rethrown unchanged if it already is a QTSError
    • percent

      public static Double percent(Integer size, Integer completed)
      Completion percentage, or null when the job does not expose enough size information to compute one.
      Parameters:
      size - total units of work
      completed - units finished so far
      Returns:
      0-100, or null