logs_cache.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 materialize.buildkite_insights.buildkite_api import logs_api
  10. from materialize.buildkite_insights.cache import generic_cache
  11. from materialize.buildkite_insights.cache.cache_constants import FetchMode
  12. from materialize.buildkite_insights.cache.generic_cache import CacheFilePath
  13. def get_or_download_log(
  14. pipeline_slug: str,
  15. fetch_mode: FetchMode,
  16. build_number: int,
  17. job_id: str,
  18. ) -> str:
  19. cache_file_path = _get_file_path_for_log(pipeline_slug=pipeline_slug, job_id=job_id)
  20. action = lambda: logs_api.download_log(
  21. pipeline_slug=pipeline_slug,
  22. build_number=build_number,
  23. job_id=job_id,
  24. )
  25. return generic_cache.get_or_query_data(
  26. cache_file_path,
  27. action,
  28. fetch_mode,
  29. max_allowed_cache_age_in_hours=96,
  30. quiet_mode=True,
  31. )
  32. def _get_file_path_for_log(
  33. pipeline_slug: str,
  34. job_id: str,
  35. ) -> CacheFilePath:
  36. return CacheFilePath(
  37. cache_item_type="log",
  38. pipeline_slug=pipeline_slug,
  39. params_hash=job_id,
  40. file_extension="txt",
  41. )