Skip to content

Commit 2b743db

Browse files
committed
Update apps.py
1 parent 2104ed6 commit 2b743db

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

src/mas/devops/mas/apps.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ def verifyAppInstance(dynClient: DynamicClient, instanceId: str, applicationId:
9898
return getAppResource(dynClient, instanceId, applicationId) is not None
9999

100100

101-
def waitForAppReady(dynClient: DynamicClient, instanceId: str, applicationId: str, workspaceId: str = None, retries: int = 100, delay: int = 600) -> bool:
101+
def waitForAppReady(
102+
dynClient: DynamicClient,
103+
instanceId: str,
104+
applicationId: str,
105+
workspaceId: str = None,
106+
retries: int = 100,
107+
delay: int = 600,
108+
debugLogFunction=logger.debug,
109+
infoLogFunction=logger.info) -> bool:
102110
"""
103111
Docstring for waitForAppReady
104112
@@ -117,6 +125,7 @@ def waitForAppReady(dynClient: DynamicClient, instanceId: str, applicationId: st
117125
:return: Description
118126
:rtype: bool
119127
"""
128+
120129
resourceName = f"{APP_KINDS[applicationId]}/{instanceId}"
121130
if workspaceId is not None:
122131
resourceName = f"{APPWS_KINDS[applicationId]}/{instanceId}-{workspaceId}"
@@ -125,43 +134,43 @@ def waitForAppReady(dynClient: DynamicClient, instanceId: str, applicationId: st
125134
appStatus = None
126135

127136
attempt = 0
128-
logger.info(f"Polling for {resourceName} to report ready state")
137+
infoLogFunction(f"Polling for {resourceName} to report ready state with {delay}s delay and {retries} retry limit")
129138

130139
while attempt < retries:
131140
attempt += 1
132141
appCR = getAppResource(dynClient, instanceId, applicationId, workspaceId)
133142

134143
if appCR is None:
135-
logger.info(f"[{attempt}/{retries}] {resourceName} does not exist")
144+
infoLogFunction(f"[{attempt}/{retries}] {resourceName} does not exist")
136145
else:
137146
appStatus = appCR.status
138147
if appStatus is None:
139-
logger.info(f"[{attempt}/{retries}] {resourceName} has no status")
148+
infoLogFunction(f"[{attempt}/{retries}] {resourceName} has no status")
140149
else:
141150
if appStatus.conditions is None:
142-
logger.info(f"[{attempt}/{retries}] {resourceName} has no status conditions")
151+
infoLogFunction(f"[{attempt}/{retries}] {resourceName} has no status conditions")
143152
else:
144153
foundReadyCondition: bool = False
145154
for condition in appStatus.conditions:
146155
if condition.type == "Ready":
147156
foundReadyCondition = True
148157
if condition.status == "True":
149-
logger.info(f"[{attempt}/{retries}] {resourceName} is in ready state: {condition.message}")
150-
logger.debug(f"CR status={json.dumps(appStatus.to_dict())}")
158+
infoLogFunction(f"[{attempt}/{retries}] {resourceName} is in ready state: {condition.message}")
159+
debugLogFunction(f"{resourceName} status={json.dumps(appStatus.to_dict())}")
151160
return True
152161
else:
153-
logger.info(f"[{attempt}/{retries}] {resourceName} is not in ready state: {condition.message}")
162+
infoLogFunction(f"[{attempt}/{retries}] {resourceName} is not in ready state: {condition.message}")
154163
continue
155164
if not foundReadyCondition:
156-
logger.info(f"[{attempt}/{retries}] {resourceName} has no ready status condition")
165+
infoLogFunction(f"[{attempt}/{retries}] {resourceName} has no ready status condition")
157166
sleep(delay)
158167

159168
# If we made it this far it means that the application was not ready in time
160169
logger.warning(f"Retry limit reached polling for {resourceName} to report ready state")
161170
if appStatus is None:
162-
logger.debug("No CR status available")
171+
infoLogFunction(f"No {resourceName} status available")
163172
else:
164-
logger.debug(f"CR status={json.dumps(appStatus.to_dict())}")
173+
debugLogFunction(f"{resourceName} status={json.dumps(appStatus.to_dict())}")
165174
return False
166175

167176

0 commit comments

Comments
 (0)