Skip to content

Commit

Permalink
Adding retry logic to contianer_healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Mar 6, 2021
1 parent e3d31bd commit 36ee5a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The following example will run a full pipeline (tests, build and deploy), tag it
}
```

* 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`).
* 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`).
* Optional: `dockerfile` value can be passed to specify the name of the Dockerfile to build from (including path if not in root directory).

**Possible Pipeline Values**
Expand Down
23 changes: 12 additions & 11 deletions harvey/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,26 @@ def build_deploy_compose(cls, config, webhook, output):
return final_output

@classmethod
def run_container_healthcheck(cls, webhook):
def run_container_healthcheck(cls, webhook, retry_attempt=0):
"""Run a healthcheck to ensure the container is running and not in a transitory state.
Not to be confused with the Docker Healthcheck functionality which is different
"""
print('Running container healthcheck...')
time.sleep(5)
print('Running container healthcheck...') # TODO: Attach project name to this line

# If we cannot inspect a container, it may not be up and running yet, retry
container = Container.inspect_container(Global.docker_project_name(webhook))
container_json = container.json()
state = container_json['State']
if (
state['Restarting']
and state['Dead']
and state['Paused']
) is False and state['Running'] is True:
state = container_json.get('State')
if not state and retry_attempt <= 5:
retry_attempt += 1
time.sleep(5)
cls.run_container_healthcheck(webhook, retry_attempt)
elif state['Running'] is True:
healthcheck = True
output = 'Project healthcheck succeeded!'
print(output)
else:
healthcheck = False
output = 'Project healthcheck failed.'
print(output)

print(output)
return healthcheck, output

0 comments on commit 36ee5a2

Please sign in to comment.