Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 36ee5a2

Browse files
committed
Adding retry logic to contianer_healthcheck
1 parent e3d31bd commit 36ee5a2

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The following example will run a full pipeline (tests, build and deploy), tag it
2626
}
2727
```
2828

29-
* Optional: `compose` value can be passed to specify the `docker-compose` file to use **if** building from a docker-compose file and hitting the `/pipelines/start/compose` endpoint (eg: `-f docker-compose.yml -f docker-compose-prod.yml`).
29+
* Optional: `compose` value can be passed to specify the `docker-compose` file to use **if** building from a docker-compose file and hitting the `/pipelines/start/compose` endpoint (eg: `docker-compose.yml -f docker-compose-prod.yml`).
3030
* Optional: `dockerfile` value can be passed to specify the name of the Dockerfile to build from (including path if not in root directory).
3131

3232
**Possible Pipeline Values**

harvey/stage.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,25 +240,26 @@ def build_deploy_compose(cls, config, webhook, output):
240240
return final_output
241241

242242
@classmethod
243-
def run_container_healthcheck(cls, webhook):
243+
def run_container_healthcheck(cls, webhook, retry_attempt=0):
244244
"""Run a healthcheck to ensure the container is running and not in a transitory state.
245245
Not to be confused with the Docker Healthcheck functionality which is different
246246
"""
247-
print('Running container healthcheck...')
248-
time.sleep(5)
247+
print('Running container healthcheck...') # TODO: Attach project name to this line
248+
249+
# If we cannot inspect a container, it may not be up and running yet, retry
249250
container = Container.inspect_container(Global.docker_project_name(webhook))
250251
container_json = container.json()
251-
state = container_json['State']
252-
if (
253-
state['Restarting']
254-
and state['Dead']
255-
and state['Paused']
256-
) is False and state['Running'] is True:
252+
state = container_json.get('State')
253+
if not state and retry_attempt <= 5:
254+
retry_attempt += 1
255+
time.sleep(5)
256+
cls.run_container_healthcheck(webhook, retry_attempt)
257+
elif state['Running'] is True:
257258
healthcheck = True
258259
output = 'Project healthcheck succeeded!'
259-
print(output)
260260
else:
261261
healthcheck = False
262262
output = 'Project healthcheck failed.'
263-
print(output)
263+
264+
print(output)
264265
return healthcheck, output

0 commit comments

Comments
 (0)