@@ -375,6 +375,20 @@ def generate_cloud_function_code( |
375 | 375 | ) |
376 | 376 | return entry_point |
377 | 377 |
|
| 378 | + @google.api_core.retry.Retry( |
| 379 | + predicate=google.api_core.retry.if_exception_type(ValueError), |
| 380 | + initial=1.0, |
| 381 | + maximum=10.0, |
| 382 | + multiplier=2.0, |
| 383 | + deadline=300.0, # Wait up to 5 minutes for propagation |
| 384 | + ) |
| 385 | + def _get_cloud_function_endpoint_with_retry(self, name): |
| 386 | + endpoint = self.get_cloud_function_endpoint(name) |
| 387 | + if not endpoint: |
| 388 | + # Raising ValueError triggers the retry predicate |
| 389 | + raise ValueError(f"Endpoint for {name} not yet available.") |
| 390 | + return endpoint |
| 391 | + |
378 | 392 | def create_cloud_function( |
379 | 393 | self, |
380 | 394 | def_, |
@@ -516,11 +530,14 @@ def create_cloud_function( |
516 | 530 | create_function_request.function = function |
517 | 531 |
|
518 | 532 | # Create the cloud function and wait for it to be ready to use |
| 533 | + endpoint = None |
519 | 534 | try: |
520 | 535 | operation = self._cloud_functions_client.create_function( |
521 | 536 | request=create_function_request |
522 | 537 | ) |
523 | | - operation.result() |
| 538 | + # operation.result() returns the Function object upon completion |
| 539 | + function_obj = operation.result() |
| 540 | + endpoint = function_obj.service_config.uri |
524 | 541 |
|
525 | 542 | # Cleanup |
526 | 543 | os.remove(archive_path) |
@@ -535,12 +552,14 @@ def create_cloud_function( |
535 | 552 | # we created it. This error is safe to ignore. |
536 | 553 | pass |
537 | 554 |
|
538 | | - # Fetch the endpoint of the just created function |
539 | | - endpoint = self.get_cloud_function_endpoint(random_name) |
| 555 | + # Fetch the endpoint with retries if it wasn't returned by the operation |
540 | 556 | if not endpoint: |
541 | | - raise bf_formatting.create_exception_with_feedback_link( |
542 | | - ValueError, "Couldn't fetch the http endpoint." |
543 | | - ) |
| 557 | + try: |
| 558 | + endpoint = self._get_cloud_function_endpoint_with_retry(random_name) |
| 559 | + except Exception as e: |
| 560 | + raise bf_formatting.create_exception_with_feedback_link( |
| 561 | + ValueError, f"Couldn't fetch the http endpoint: {e}" |
| 562 | + ) |
544 | 563 |
|
545 | 564 | logger.info( |
546 | 565 | f"Successfully created cloud function {random_name} with uri ({endpoint})" |
|