Package com.qtsurfer.api.sdk.internal
Class Polling
java.lang.Object
com.qtsurfer.api.sdk.internal.Polling
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 Summary
Modifier and TypeMethodDescriptionstatic DoubleCompletion percentage, ornullwhen the job does not expose enough size information to compute one.static <T> Tpoll(String stage, Duration pollInterval, Duration maxPollInterval, Duration timeout, Supplier<T> fetch, Predicate<T> retryWhile, Consumer<T> onResult) PollfetchuntilretryWhilestops matching, then return the last result.
-
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) PollfetchuntilretryWhilestops matching, then return the last result.- Type Parameters:
T- polled state type- Parameters:
stage- label used in the timeout message, e.g.PREPARINGpollInterval- initial interval between attemptsmaxPollInterval- upper bound of the exponential backofftimeout- overall deadline for this stage;nulldisablesfetch- reads the current stateretryWhile-truewhile the state is not terminalonResult- called with every attempt's result, terminal or not; may benull- Returns:
- the first result
retryWhilerejected - Throws:
QTSTimeoutError- when the stage outlivestimeoutQTSCanceledError- when the polling thread is interruptedQTSError- whenfetchfails; the original error is rethrown unchanged if it already is aQTSError
-
percent
Completion percentage, ornullwhen the job does not expose enough size information to compute one.- Parameters:
size- total units of workcompleted- units finished so far- Returns:
- 0-100, or
null
-