Skip to content

Commit

Permalink
feat(project): waits for project to succeed during apply
Browse files Browse the repository at this point in the history
This commit adds a wait after the project is created to check if it has
entered the succeeded state. The wait will time out if it doesn't
succeed within the specified timeout.
  • Loading branch information
pallabpain committed May 9, 2023
1 parent 981dc3a commit adb004b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pyrfc3339 = ">=1.1"
directory-tree = ">=0.0.3.1"
yaspin = ">=2.3.0"
jsonschema = ">=4.0.0"
waiting = ">=1.4.1"

[requires]
python_version = "3"
11 changes: 9 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions riocli/project/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

from munch import unmunchify
from rapyuta_io import Client
from waiting import wait, TimeoutExpired

from riocli.config import new_v2_client, Configuration
from riocli.jsonschema.validate import load_schema
from riocli.model import Model

PROJECT_READY_TIMEOUT = 150

class Project(Model):

Expand Down Expand Up @@ -48,6 +50,12 @@ def create_object(self, client: Client) -> typing.Any:
'organization_id']

r = client.create_project(project)

try:
wait(self.is_ready, timeout_seconds=PROJECT_READY_TIMEOUT, sleep_seconds=(1, 30, 2))
except TimeoutExpired as e:
raise e

return unmunchify(r)

def update_object(self, client: Client, obj: typing.Any) -> typing.Any:
Expand All @@ -66,6 +74,11 @@ def delete_object(self, client: Client, obj: typing.Any) -> typing.Any:
client = new_v2_client()
client.delete_project(obj.metadata.guid)

def is_ready(self) -> bool:
client = new_v2_client()
projects = client.list_projects(query={"name": self.metadata.name})
return projects[0].status.status == 'Success'

@classmethod
def pre_process(cls, client: Client, d: typing.Dict) -> None:
pass
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"directory-tree>=0.0.3.1",
"yaspin>=2.3.0",
"jsonschema>=4.0.0"
"waiting>=1.4.1"
],
setup_requires=["flake8"],
)

0 comments on commit adb004b

Please sign in to comment.