deploy_await.sql 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. -- Copyright Materialize, Inc. and contributors. All rights reserved.
  2. --
  3. -- Licensed under the Apache License, Version 2.0 (the "License");
  4. -- you may not use this file except in compliance with the License.
  5. -- You may obtain a copy of the License in the LICENSE file at the
  6. -- root of this repository, or online at
  7. --
  8. -- http://www.apache.org/licenses/LICENSE-2.0
  9. --
  10. -- Unless required by applicable law or agreed to in writing, software
  11. -- distributed under the License is distributed on an "AS IS" BASIS,
  12. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. -- See the License for the specific language governing permissions and
  14. -- limitations under the License.
  15. {% macro deploy_await(poll_interval=15, lag_threshold='1s') %}
  16. {#
  17. Waits for all objects within the deployment clusters to be fully hydrated,
  18. polling the cluster's readiness status at a specified interval.
  19. ## Arguments
  20. - `poll_interval` (integer): The interval, in seconds, between each readiness
  21. check.
  22. - `lag_threshold` (string): The maximum lag threshold, which determines when
  23. all objects in the environment are considered hydrated and it''s safe to
  24. perform the cutover step.
  25. ## Returns None: This macro does not return a value but will halt execution
  26. until the specified cluster's objects are fully hydrated.
  27. #}
  28. {% set current_target_name = target.name %}
  29. {% set deployment = var('deployment') %}
  30. {% set target_config = deployment[current_target_name] %}
  31. -- Check if the target-specific configuration exists
  32. {% if not target_config %}
  33. {{ exceptions.raise_compiler_error("No deployment configuration found for target " ~ current_target_name) }}
  34. {% endif %}
  35. {% set clusters = target_config.get('clusters', []) %}
  36. {% for cluster in clusters %}
  37. {% set deploy_cluster = adapter.generate_final_cluster_name(cluster, force_deploy_suffix=True) %}
  38. {{ await_cluster_ready(deploy_cluster, poll_interval, lag_threshold) }}
  39. {% endfor %}
  40. {% endmacro %}