ProgressLogger needs to completed even if exception is thrown
@@ -22,6 +22,7 @@ import com.github.dockerjava.api.command.InspectContainerResponse
import org.gradle.api.GradleException
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
+import org.gradle.internal.logging.progress.ProgressLogger
import java.util.concurrent.TimeUnit
@@ -61,12 +62,13 @@ class DockerLivenessContainer extends DockerLogsContainer {
// if livenessProbe was defined proceed as expected otherwise just
// check if the container is up and running
if (livenessProbe) {
-
// create progressLogger for pretty printing of terminal log progression
- final def progressLogger = getProgressLogger(project, DockerLivenessContainer)
+ ProgressLogger progressLogger = getProgressLogger(project, DockerLivenessContainer)
progressLogger.started()
boolean matchFound = false
+
+ try {
long localPollTime = livenessProbe.pollTime
int pollTimes = 0
@@ -80,10 +82,7 @@ class DockerLivenessContainer extends DockerLogsContainer {
pollTimes += 1
// 2.) check if container is actually running
- lastInspection = dockerClient.inspectContainerCmd(containerId.get()).exec()
- if (lastInspection.getState().getRunning() == false) {
- throw new GradleException("Container with ID '${containerId.get()}' is not running and so can't perform liveness probe.");
- }
+ lastInspection = inspectContainer()
if (lastDate) {
this.internalSince = lastDate
@@ -103,12 +102,10 @@ class DockerLivenessContainer extends DockerLogsContainer {
matchFound = true
break
} else {
-
long totalMillis = pollTimes * livenessProbe.pollInterval
long totalMinutes = TimeUnit.MILLISECONDS.toMinutes(totalMillis)
progressLogger.progress("Probing for ${totalMinutes}m...")
try {
-
// zero'ing out the below so as to save on memory for potentially
// big logs returned from container.
logLine = null
@@ -121,17 +118,26 @@ class DockerLivenessContainer extends DockerLogsContainer {
}
}
}
+ } finally {
progressLogger.completed()
+ }
if (!matchFound) {
throw new GradleException("Liveness probe failed to find a match: ${livenessProbe.toString()}")
}
} else {
- lastInspection = dockerClient.inspectContainerCmd(containerId.get()).exec()
- if (lastInspection.getState().getRunning() == false) {
- throw new GradleException("Container with ID '${containerId.get()}' is not running.");
+ lastInspection = inspectContainer()
+ }
}
+
+ private InspectContainerResponse inspectContainer() {
+ InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(containerId.get()).exec()
+
+ if (!inspectContainerResponse.getState().getRunning()) {
+ throw new GradleException("Container with ID '${containerId.get()}' is not running.");
}
+
+ inspectContainerResponse
}
/**
