annotations_cache.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from typing import Any
  10. from materialize.buildkite_insights.buildkite_api import annotations_api
  11. from materialize.buildkite_insights.cache import generic_cache
  12. from materialize.buildkite_insights.cache.cache_constants import FetchMode
  13. from materialize.buildkite_insights.cache.generic_cache import CacheFilePath
  14. def get_or_query_annotations(
  15. fetch_mode: FetchMode,
  16. pipeline_slug: str,
  17. build_number: str,
  18. add_to_cache_if_not_present: bool,
  19. quiet_mode: bool = True,
  20. ) -> list[Any]:
  21. cache_file_path = CacheFilePath(
  22. cache_item_type="annotations",
  23. pipeline_slug=pipeline_slug,
  24. params_hash=build_number,
  25. )
  26. fetch_action = lambda: annotations_api.get_annotations(
  27. pipeline_slug=pipeline_slug,
  28. build_number=build_number,
  29. )
  30. return generic_cache.get_or_query_data(
  31. cache_file_path,
  32. fetch_action,
  33. fetch_mode,
  34. max_allowed_cache_age_in_hours=None,
  35. add_to_cache_if_not_present=add_to_cache_if_not_present,
  36. quiet_mode=quiet_mode,
  37. )