Skip to content

Commit

Permalink
Improve wait for build
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreLobato committed Jan 16, 2025
1 parent 0dc46bb commit c85defa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
42 changes: 30 additions & 12 deletions src/oceanum/cli/prax/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,25 @@ def _wait_builds_to_finish(self, **params):
if isinstance(project, models.ProjectSchema) and project.last_revision is not None:
params['project'] = params.pop('project_name', project.name)
project_builds = self.list_builds(**params)

if not isinstance(project_builds, list):
click.echo(f" {err} Failed to get project builds!")
return False
spec = project.last_revision.spec
builds = spec.resources.builds if spec.resources else None

if not builds:
click.echo(f" {chk} No builds found in project '{project.name}'!")
return False
return True

while builds and project_builds == []:
click.echo(f" {spin} Waiting for builds to start '{project.name}'!")
while builds and (project_builds == [] or all([p.last_run is None for p in project_builds])):
click.echo(f" {spin} Waiting for builds to start...")
time.sleep(self._lag)
project_builds = self.list_builds(**params)
print (project_builds)
if not isinstance(project_builds, list):
click.echo(f" {err} Failed to get project builds!")
return False

if isinstance(project_builds, list):
running_builds = [b for b in project_builds if b.last_run and b.last_run.status in ['Pending','Running']]
while any(running_builds):
Expand All @@ -195,9 +202,18 @@ def _wait_builds_to_finish(self, **params):
project_builds = self.list_builds(**params)
if isinstance(project_builds, list):
running_builds = [b for b in project_builds if b.last_run and b.last_run.status in ['Pending','Running']]

click.echo(f" {chk} All builds finished!")
return True
if builds and project_builds:
click.echo(f" {chk} All builds finished!")
if isinstance(project_builds, list):
for build in project_builds:
if build.last_run and build.last_run.status in ['Failed','Error']:
click.echo(f" {err} Build '{build.name}' failed to start or while running!")
click.echo(f"Inspect Build Run with 'oceanum prax describe build {build.name} --project {project.name} --org {project.org} --stage {build.stage}'!")
return False
return True
else:
click.echo(f" {err} Failed to get project details!")
return False

def _wait_stages_finish_updating(self, **params):
counter = 0
Expand Down Expand Up @@ -281,12 +297,14 @@ def wait_project_deployment(self, **params) -> bool:
start = time.time()
committed = self._wait_project_commit(**params)
if committed:
self._wait_stages_start_updating(**params)
self._wait_builds_to_finish(**params)
self._wait_stages_finish_updating(**params)
self._check_routes(**params)
started_updating = self._wait_stages_start_updating(**params)
build_succeeded = self._wait_builds_to_finish(**params)
if build_succeeded:
self._wait_stages_finish_updating(**params)
self._check_routes(**params)
delta = timedelta(seconds=time.time()-start)
click.echo(f" {watch} Deployment finished in {humanize.naturaldelta(delta)}.")
with_error = "(with errors) " if not all([committed, started_updating, build_succeeded]) else " "
click.echo(f" {watch} Deployment finished {with_error}in {humanize.naturaldelta(delta)}.")
return True

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/oceanum/cli/prax/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def validate_project(ctx: click.Context, specfile: click.Path):
@login_required
def deploy_project(
ctx: click.Context,
specfile: click.Path,
specfile: click.Path,
name: str|None,
org: str|None,
user: str|None,
Expand Down

0 comments on commit c85defa

Please sign in to comment.