Browse Source

Two minor cleanup items (#211)

davidfowl/dependencies
Justin Kotalik 7 years ago
committed by GitHub
parent
commit
4aa3470389
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/Microsoft.Tye.Hosting/DockerRunner.cs

13
src/Microsoft.Tye.Hosting/DockerRunner.cs

@ -15,6 +15,7 @@ namespace Microsoft.Tye.Hosting
{
public class DockerRunner : IApplicationProcessor
{
private static readonly TimeSpan DockerStopTimeout = TimeSpan.FromSeconds(30);
private readonly ILogger _logger;
public DockerRunner(ILogger logger)
@ -207,12 +208,17 @@ namespace Microsoft.Tye.Hosting
_logger.LogInformation("docker logs collection for {ContainerName} complete with exit code {ExitCode}", replica, result.ExitCode);
// Docker has a tendency to get stuck so we're going to timeout this shutdown process
var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var timeoutCts = new CancellationTokenSource(DockerStopTimeout);
_logger.LogInformation("Stopping container {ContainerName} with ID {ContainerId}", replica, shortContainerId);
result = await ProcessUtil.RunAsync("docker", $"stop {containerId}", throwOnError: false, cancellationToken: timeoutCts.Token);
if (timeoutCts.IsCancellationRequested)
{
_logger.LogWarning($"Failed to stop container after {DockerStopTimeout.Seconds} seconds, container will most likely be running.", replica, shortContainerId);
}
PrintStdOutAndErr(service, replica, result);
service.ReplicaEvents.OnNext(new ReplicaEvent(ReplicaState.Stopped, status));
@ -221,6 +227,11 @@ namespace Microsoft.Tye.Hosting
result = await ProcessUtil.RunAsync("docker", $"rm {containerId}", throwOnError: false, cancellationToken: timeoutCts.Token);
if (timeoutCts.IsCancellationRequested)
{
_logger.LogWarning($"Failed to remove container after {DockerStopTimeout.Seconds} seconds, container will most likely still exist.", replica, shortContainerId);
}
PrintStdOutAndErr(service, replica, result);
_logger.LogInformation("Removed container {ContainerName} with ID {ContainerId} exited with {ExitCode}", replica, shortContainerId, result.ExitCode);

Loading…
Cancel
Save