diff --git a/src/ota_proxy/cache_streaming.py b/src/ota_proxy/cache_streaming.py index 48237dc0d..17e14b02f 100644 --- a/src/ota_proxy/cache_streaming.py +++ b/src/ota_proxy/cache_streaming.py @@ -335,6 +335,7 @@ async def cache_streaming( Raises: CacheStreamingFailed if any exception happens during retrieving. """ + _cache_write_gen = None try: _cache_write_gen = await tracker.start_provider(cache_meta) _cache_writer_failed = False @@ -370,8 +371,9 @@ async def cache_streaming( finally: # force terminate the generator in all condition at exit, this # can ensure the generator being gced after cache_streaming exits. - with contextlib.suppress(StopAsyncIteration): - await _cache_write_gen.athrow(StopAsyncIteration) + if _cache_write_gen: + with contextlib.suppress(StopAsyncIteration): + await _cache_write_gen.athrow(StopAsyncIteration) # remove the refs fd, tracker = None, None # type: ignore diff --git a/src/ota_proxy/config.py b/src/ota_proxy/config.py index a6c483877..c6b571adb 100644 --- a/src/ota_proxy/config.py +++ b/src/ota_proxy/config.py @@ -16,8 +16,8 @@ class Config: BASE_DIR = "/ota-cache" CHUNK_SIZE = 1 * 1024 * 1024 # 4MB - DISK_USE_LIMIT_SOFT_P = 70 # in p% - DISK_USE_LIMIT_HARD_P = 80 # in p% + DISK_USE_LIMIT_SOFT_P = 90 # in p% + DISK_USE_LIMIT_HARD_P = 92 # in p% DISK_USE_PULL_INTERVAL = 2 # in seconds # value is the largest numbers of files that # might need to be deleted for the bucket to hold a new entry diff --git a/src/ota_proxy/ota_cache.py b/src/ota_proxy/ota_cache.py index c68ff7731..531525cd9 100644 --- a/src/ota_proxy/ota_cache.py +++ b/src/ota_proxy/ota_cache.py @@ -248,7 +248,7 @@ def _background_check_free_space(self): self._storage_below_hard_limit_event.clear() break - current_used_p = disk_usage.used / disk_usage.total * 100 + current_used_p = int(disk_usage.used / disk_usage.total * 100) _previous_below_hard = self._storage_below_hard_limit_event.is_set() _current_below_hard = True @@ -266,13 +266,13 @@ def _background_check_free_space(self): # logging space monitoring result if _previous_below_hard and not _current_below_hard: logger.warning( - f"disk usage reached hard limit({current_used_p=:.1}%," - f"{cfg.DISK_USE_LIMIT_HARD_P:.1}%), cache disabled" + f"disk usage reached hard limit({current_used_p=}%," + f"{cfg.DISK_USE_LIMIT_HARD_P=}%), cache disabled" ) elif not _previous_below_hard and _current_below_hard: logger.info( - f"disk usage is below hard limit({current_used_p=:.1}%)," - f"{cfg.DISK_USE_LIMIT_SOFT_P:.1}%), cache enabled again" + f"disk usage is below hard limit({current_used_p=}%)," + f"{cfg.DISK_USE_LIMIT_SOFT_P=}%), cache enabled again" ) time.sleep(cfg.DISK_USE_PULL_INTERVAL)