Don't error when killing/removing non-existent cotainer
We don't need these on sentry
@@ -14,6 +14,7 @@ from django.utils.translation import ugettext_lazy as _
from docker import APIClient
from docker.errors import APIError as DockerAPIError
from docker.errors import DockerException
+from docker.errors import NotFound as DockerNotFoundError
from requests.exceptions import ConnectionError
from requests_toolbelt.multipart.encoder import MultipartEncoder
from slumber.exceptions import HttpClientError
@@ -872,16 +873,27 @@ class DockerBuildEnvironment(BuildEnvironment):
client = self.get_client()
try:
client.kill(self.container_id)
+ except DockerNotFoundError:
+ log.info(
+ 'Container does not exists, nothing to kill. id=%s',
+ self.container_id,
+ )
except DockerAPIError:
log.exception(
'Unable to kill container: id=%s',
self.container_id,
)
+
try:
log.info('Removing container: id=%s', self.container_id)
client.remove_container(self.container_id)
- # Catch direct failures from Docker API or with a requests HTTP
- # request. These errors should not surface to the user.
+ except DockerNotFoundError:
+ log.info(
+ 'Container does not exists, nothing to remove. id=%s',
+ self.container_id,
+ )
+ # Catch direct failures from Docker API or with an HTTP request.
+ # These errors should not surface to the user.
except (DockerAPIError, ConnectionError):
log.exception(
LOG_TEMPLATE,
