Skip to content

Commit

Permalink
Add unhealthy state
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <[email protected]>
  • Loading branch information
docjyJ committed Oct 8, 2024
1 parent 531104d commit 6a3c340
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions php/src/Container/ContainerState.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ enum ContainerState: string {
case Running = 'running';
case Starting = 'starting';
case Stopped = 'stopped';
case Unhealthy = 'unhealthy';
}
8 changes: 5 additions & 3 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public function GetContainerRunningState(Container $container) : ContainerState

$responseBody = json_decode((string)$response->getBody(), true);

if ($responseBody['State']['Running'] === true) {
return ContainerState::Running;
} else {
if ($responseBody['State']['Running'] !== true) {
return ContainerState::Stopped;
} elseif(array_key_exists('Health', $responseBody['State']) && $responseBody['State']['Health']['Status'] !== 'healthy') {
return ContainerState::Unhealthy;
} else {
return ContainerState::Running;
}
}

Expand Down
7 changes: 7 additions & 0 deletions php/templates/containers.twig
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@
(<a href="{{ container.GetDocumentation() }}">docs</a>)
{% endif %}
</span>
{% elseif container.GetRunningState().value == 'unhealthy' %}
<span class="status running"></span>
<span>{{ container.GetDisplayName() }} (<a href="/api/docker/logs?id={{ container.GetIdentifier() }}" target="_blank" rel="noopener">Unhealthy</a>)
{% if container.GetDocumentation() != '' %}
(<a href="{{ container.GetDocumentation() }}">docs</a>)
{% endif %}
</span>
{% elseif container.GetRunningState().value == 'running' %}
<span class="status success"></span>
<span>{{ container.GetDisplayName() }} (<a href="/api/docker/logs?id={{ container.GetIdentifier() }}" target="_blank" rel="noopener">Running</a>)
Expand Down

0 comments on commit 6a3c340

Please sign in to comment.