Merge branch 'fix-60-second-try-container-already-in-progress' into 'main'

[Fix]  container already in progress (second try)

Closes #60

See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!94
This commit is contained in:
Rémy Taymans 2024-10-08 14:00:17 +00:00
commit 6b7f1d008f

View File

@ -1,3 +1,5 @@
import time
import docker
from loguru import logger
@ -110,6 +112,28 @@ def exec_container(container, command):
def kill_container(container_name):
# In some situation, containers.list return
# containers with removal already in progress
# when we call container.remove(), it is raising an
# docker.errors.APIError
# "removal of container xx is already in progress".
# so, we retry a few seconds after
# and raise an exception after five failures.
for i in [1, 5, 10, 60, False]:
try:
_kill_container(container_name)
return
except docker.errors.APIError as e:
if not i:
logger.error(f"Fail to kill {container_name} after 5 retries")
raise e
logger.warning(
f"Fail to kill {container_name}. Retrying in {i} seconds"
)
time.sleep(i)
def _kill_container(container_name):
client = get_docker_client()
try: