Search in sources :

Example 1 with Backoff

use of org.batfish.common.util.Backoff in project batfish by batfish.

the class Client method pollWork.

private boolean pollWork(UUID wItemId, @Nullable FileWriter outWriter) {
    Pair<WorkStatusCode, String> response;
    try (ActiveSpan workStatusSpan = GlobalTracer.get().buildSpan("Waiting for work status").startActive()) {
        // avoid unused warning
        assert workStatusSpan != null;
        // Poll the work item until it finishes or fails.
        response = _workHelper.getWorkStatus(wItemId);
        if (response == null) {
            return false;
        }
        WorkStatusCode status = response.getFirst();
        Backoff backoff = Backoff.builder().withMaximumBackoff(Duration.ofSeconds(1)).build();
        while (!status.isTerminated() && backoff.hasNext()) {
            printWorkStatusResponse(response, false);
            try {
                Thread.sleep(backoff.nextBackoff().toMillis());
            } catch (InterruptedException e) {
                throw new BatfishException("Interrupted while waiting for work item to complete", e);
            }
            response = _workHelper.getWorkStatus(wItemId);
            if (response == null) {
                return false;
            }
            status = response.getFirst();
        }
        printWorkStatusResponse(response, false);
    }
    return true;
}
Also used : BatfishException(org.batfish.common.BatfishException) WorkStatusCode(org.batfish.common.CoordConsts.WorkStatusCode) ActiveSpan(io.opentracing.ActiveSpan) Backoff(org.batfish.common.util.Backoff)

Aggregations

ActiveSpan (io.opentracing.ActiveSpan)1 BatfishException (org.batfish.common.BatfishException)1 WorkStatusCode (org.batfish.common.CoordConsts.WorkStatusCode)1 Backoff (org.batfish.common.util.Backoff)1