Skip to content

Commit

Permalink
Properly wait for s2i build to complete
Browse files Browse the repository at this point in the history
Furthermore, Ensure that the executor used is shutdown

Co-authored-by: George Gastaldi <[email protected]>
  • Loading branch information
geoand and gastaldi committed Nov 10, 2022
1 parent 9fc44a4 commit 1d82193
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
Expand Down Expand Up @@ -372,19 +373,33 @@ private static void s2iBuild(OpenShiftClient client, BuildConfig buildConfig, Fi
}

private static void waitForBuildComplete(OpenShiftClient client, S2iConfig s2iConfig, String buildName, Closeable watch) {
Executor executor = Executors.newSingleThreadExecutor();
CountDownLatch latch = new CountDownLatch(1);
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
try {
client.builds().withName(buildName).waitUntilCondition(b -> !RUNNING.equalsIgnoreCase(b.getStatus().getPhase()),
s2iConfig.buildTimeout.toMillis(), TimeUnit.MILLISECONDS);
} finally {
try {
watch.close();
} catch (IOException e) {
LOG.debug("Error closing log reader.");
}
latch.countDown();
}
});
try {
latch.await();
} catch (InterruptedException e) {
LOG.debug("Error waiting for build to complete.", e);
} finally {
try {
watch.close();
} catch (IOException e) {
LOG.debug("Error closing log reader.", e);
}
try {
executor.shutdown();
} catch (Exception e) {
LOG.debug("Error shutting down executor", e);
}
}

}

public static Predicate<HasMetadata> distinctByResourceKey() {
Expand Down

0 comments on commit 1d82193

Please sign in to comment.