Code review comment: Are there perhaps environments that need a longer time to spin up the services? Would only lower to 1 minute.

Code before review:
public RemoteEnvironment createEnvironment(Environment environment) throws Exception {
Preconditions.checkState(
environment
.getUrn()
.equals(BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER)),
"The passed environment does not contain a DockerPayload.");
final RunnerApi.DockerPayload dockerPayload =
RunnerApi.DockerPayload.parseFrom(environment.getPayload());
final String workerId = idGenerator.getId();
String containerImage = dockerPayload.getContainerImage();
String loggingEndpoint = loggingServiceServer.getApiServiceDescriptor().getUrl();
String artifactEndpoint = retrievalServiceServer.getApiServiceDescriptor().getUrl();
String provisionEndpoint = provisioningServiceServer.getApiServiceDescriptor().getUrl();
String controlEndpoint = controlServiceServer.getApiServiceDescriptor().getUrl();
ImmutableList.Builder<String> dockerArgsBuilder =
ImmutableList.<String>builder()
.addAll(gcsCredentialArgs())
.add("--network=host")
.add("--env=DOCKER_MAC_CONTAINER=" + System.getenv("DOCKER_MAC_CONTAINER"));
if (!retainDockerContainer) {
dockerArgsBuilder.add("--rm");
}
List<String> args =
ImmutableList.of(
String.format("--id=%s", workerId),
String.format("--logging_endpoint=%s", loggingEndpoint),
String.format("--artifact_endpoint=%s", artifactEndpoint),
String.format("--provision_endpoint=%s", provisionEndpoint),
String.format("--control_endpoint=%s", controlEndpoint));
LOG.debug("Creating Docker Container with ID {}", workerId);
String containerId = null;
InstructionRequestHandler instructionHandler = null;
try {
containerId = docker.runImage(containerImage, dockerArgsBuilder.build(), args);
LOG.debug("Created Docker Container with Container ID {}", containerId);
while (instructionHandler == null) {
Preconditions.checkArgument(
docker.isContainerRunning(containerId), "No container running for id " + containerId);
try {
instructionHandler = clientSource.take(workerId, Duration.ofSeconds(30));
} catch (TimeoutException timeoutEx) {
LOG.info(
"Still waiting for startup of environment {} for worker id {}",
dockerPayload.getContainerImage(),
workerId);
} catch (InterruptedException interruptEx) {
Thread.currentThread().interrupt();
throw new RuntimeException(interruptEx);
}
}
} catch (Exception e) {
if (containerId != null) {
try {
docker.killContainer(containerId);
} catch (Exception dockerException) {
e.addSuppressed(dockerException);
}
}
throw e;
}
return DockerContainerEnvironment.create(docker, environment, containerId, instructionHandler);
}

Line under review: instructionHandler = clientSource.take(workerId, Duration.ofSeconds(30));

Code after addressing the review:
public RemoteEnvironment createEnvironment(Environment environment) throws Exception {
Preconditions.checkState(
environment
.getUrn()
.equals(BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER)),
"The passed environment does not contain a DockerPayload.");
final RunnerApi.DockerPayload dockerPayload =
RunnerApi.DockerPayload.parseFrom(environment.getPayload());
final String workerId = idGenerator.getId();
String containerImage = dockerPayload.getContainerImage();
String loggingEndpoint = loggingServiceServer.getApiServiceDescriptor().getUrl();
String artifactEndpoint = retrievalServiceServer.getApiServiceDescriptor().getUrl();
String provisionEndpoint = provisioningServiceServer.getApiServiceDescriptor().getUrl();
String controlEndpoint = controlServiceServer.getApiServiceDescriptor().getUrl();
ImmutableList.Builder<String> dockerArgsBuilder =
ImmutableList.<String>builder()
.addAll(gcsCredentialArgs())
.add("--network=host")
.add("--env=DOCKER_MAC_CONTAINER=" + System.getenv("DOCKER_MAC_CONTAINER"));
if (!retainDockerContainer) {
dockerArgsBuilder.add("--rm");
}
List<String> args =
ImmutableList.of(
String.format("--id=%s", workerId),
String.format("--logging_endpoint=%s", loggingEndpoint),
String.format("--artifact_endpoint=%s", artifactEndpoint),
String.format("--provision_endpoint=%s", provisionEndpoint),
String.format("--control_endpoint=%s", controlEndpoint));
LOG.debug("Creating Docker Container with ID {}", workerId);
String containerId = null;
InstructionRequestHandler instructionHandler = null;
try {
containerId = docker.runImage(containerImage, dockerArgsBuilder.build(), args);
LOG.debug("Created Docker Container with Container ID {}", containerId);
while (instructionHandler == null) {
try {
instructionHandler = clientSource.take(workerId, Duration.ofMinutes(1));
} catch (TimeoutException timeoutEx) {
Preconditions.checkArgument(
docker.isContainerRunning(containerId), "No container running for id " + containerId);
LOG.info(
"Still waiting for startup of environment {} for worker id {}",
dockerPayload.getContainerImage(),
workerId);
} catch (InterruptedException interruptEx) {
Thread.currentThread().interrupt();
throw new RuntimeException(interruptEx);
}
}
} catch (Exception e) {
if (containerId != null) {
try {
docker.killContainer(containerId);
} catch (Exception dockerException) {
e.addSuppressed(dockerException);
}
}
throw e;
}
return DockerContainerEnvironment.create(docker, environment, containerId, instructionHandler);
}