Handle container not found exception

This commit is contained in:
Scott Wallace 2022-05-18 12:53:22 +01:00
parent f6b9282dfc
commit 8d6eb6687f
Signed by: scott
GPG key ID: AA742FDC5AFE2A72
2 changed files with 11 additions and 7 deletions

View file

@ -29,12 +29,12 @@ build-job: # This job runs in the build stage, which runs first.
- docker push $CI_REGISTRY_IMAGE
- echo "Build complete."
# unit-test-job: # This job runs in the test stage.
# stage: test
# script:
# - echo "Running unit tests..."
# - python3 -munittest discover
# - echo "Testing complete"
unit-test-job: # This job runs in the test stage.
stage: test
script:
- echo "Running unit tests..."
- python3 -munittest discover
- echo "Testing complete"
lint-test-job: # This job also runs in the test stage.
stage: test # It can run at the same time as unit-test-job (in parallel).

View file

@ -103,7 +103,11 @@ class HTTPHandler(MetricsHandler): # type: ignore[misc]
)
for container in self.docker_client.containers.list(all=True):
try:
data = self.docker_api.inspect_container(container.id)
except docker.errors.NotFound:
print(f'WARNING: Container {container.id} does not exist. Skipping.')
continue
running = bool(data['State']['Running'])
started_at = data['State']['StartedAt']