Skip to content

Commit b157106

Browse files
authored
[GCP Functions] Poll long-running operations for GCP Function deployment (#1425)
1 parent 078a507 commit b157106

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lithops/serverless/backends/gcp_functions/gcp_functions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,26 +244,26 @@ def _create_function(self, runtime_name, memory, timeout=60):
244244
'failurePolicy': {}
245245
}
246246

247-
response = self._api_resource.projects().locations().functions().create(
247+
operation = self._api_resource.projects().locations().functions().create(
248248
location=self._default_location,
249249
body=cloud_function
250250
).execute(num_retries=self.num_retries)
251251

252252
# Wait until the function is completely deployed
253253
logger.info('Waiting for the function to be deployed')
254+
operation_name = operation['name']
254255
while True:
255-
response = self._api_resource.projects().locations().functions().get(
256-
name=function_location
256+
op_status = self._api_resource.operations().get(
257+
name=operation_name
257258
).execute(num_retries=self.num_retries)
258-
logger.debug(f'Function status is {response["status"]}')
259-
if response['status'] == 'ACTIVE':
259+
if op_status.get('done'):
260+
if 'error' in op_status:
261+
raise Exception(f'Error while deploying Cloud Function: {op_status["error"]}')
262+
logger.info("Deployment completed successfully.")
260263
break
261-
elif response['status'] == 'OFFLINE':
262-
raise Exception('Error while deploying Cloud Function')
263-
elif response['status'] == 'DEPLOY_IN_PROGRESS':
264-
time.sleep(self.retry_sleep)
265264
else:
266-
raise Exception(f"Unknown status {response['status']}")
265+
logger.debug("Deployment in progress, waiting...")
266+
time.sleep(self.retry_sleep)
267267

268268
def build_runtime(self, runtime_name, requirements_file, extra_args=[]):
269269
if not requirements_file:

0 commit comments

Comments
 (0)