Skip to content

Commit

Permalink
invert retrycount
Browse files Browse the repository at this point in the history
  • Loading branch information
BarDweller committed Jul 16, 2024
1 parent 7b4698b commit 165d709
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static class ImageInfo {
/**
* Util method to pull images, configure behavior via dockerconfig.
*/
@SuppressWarnings("resource")
public static void pullImages(DockerConfig config, String... imageNames) {
Set<String> imageNameSet = new HashSet<>(Arrays.asList(imageNames));

Expand Down Expand Up @@ -65,7 +66,7 @@ public static void pullImages(DockerConfig config, String... imageNames) {
}
}

int retriesRemaining = config.getPullRetryCount();
int retryCount = 0;
Map<String,PullImageResultCallback> pircMap = new HashMap<>();

// pull the images still in set.
Expand All @@ -79,15 +80,15 @@ public static void pullImages(DockerConfig config, String... imageNames) {
// wait for pulls to complete.
RuntimeException lastSeen = null;
boolean allDone = false;
while(!allDone && retriesRemaining>=0){
while(!allDone && retryCount<=config.getPullRetryCount()){
allDone = true;
long thisWait = config.getPullTimeout()+(retryCount*config.getPullRetryIncrease());
for (Entry<String, PullImageResultCallback> e : pircMap.entrySet()) {
boolean done = false;
try {
if(e.getValue()==null) continue;
log.debug("waiting on image "+e.getKey());
int extraWait = (config.getPullRetryCount() - retriesRemaining)*config.getPullRetryIncrease();
done = e.getValue().awaitCompletion(config.getPullTimeout() + extraWait, TimeUnit.SECONDS);
log.debug("waiting on image "+e.getKey()+" for "+thisWait+" seconds");
done = e.getValue().awaitCompletion( thisWait, TimeUnit.SECONDS);
log.debug("success for image "+e.getKey());
} catch (InterruptedException ie) {
throw BuildpackException.launderThrowable(ie);
Expand All @@ -107,13 +108,13 @@ public static void pullImages(DockerConfig config, String... imageNames) {
e.setValue(null);
}
}
if(retriesRemaining>0){
retryCount++;
if(retryCount<=config.getPullRetryCount()){
if(lastSeen!=null){
log.debug("Error during pull "+lastSeen.getMessage());
}
log.debug("Retrying ("+retriesRemaining+") for "+pircMap.entrySet().stream().filter(e -> e.getValue()!=null).collect(Collectors.toList()));
log.debug("Retrying ("+retryCount+") for "+pircMap.entrySet().stream().filter(e -> e.getValue()!=null).collect(Collectors.toList()));
}
retriesRemaining-=1;
}

if(lastSeen!=null && !allDone){
Expand Down

0 comments on commit 165d709

Please sign in to comment.