Skip to content

Commit

Permalink
temp allow mithril fork
Browse files Browse the repository at this point in the history
  • Loading branch information
cong-or committed Dec 10, 2024
1 parent 6b0cf8b commit 8a28026
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
12 changes: 6 additions & 6 deletions utilities/earthly-cache-watcher/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ def get_subdirectory_name(working_dir_path: str, path: str):
working_dir_path = os.path.abspath(working_dir_path)
path = os.path.abspath(path)

if (
os.path.commonpath([working_dir_path])
!= os.path.commonpath([working_dir_path, path])
if os.path.commonpath([working_dir_path]) != os.path.commonpath(
[working_dir_path, path]
):
return None

relative_path = os.path.relpath(path, working_dir_path)
parts = relative_path.split(os.sep)

if parts:
return parts[0]
return None


def add_or_init(obj: dict[str, int], key: str, value: int):
obj.setdefault(key, 0)
obj[key] += value
obj[key] += value
28 changes: 22 additions & 6 deletions utilities/earthly-cache-watcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ def list_initial_sizes(self):
self.file_index[file_path] = size
helper.add_or_init(self.layer_index, layer_name, size)

logger.debug(f"initial file: {file_path} (size: {size:,} bytes)")
logger.debug(
f"initial file: {file_path} (size: {size:,} bytes)"
)
except OSError as e:
if log_file_accessing_err:
logger.error(f"{e}: {file_path}")
Expand Down Expand Up @@ -225,11 +227,15 @@ def check_sizes(self, layer_name: str, skip_sum_check=False):

if (
not skip_sum_check
and sum(self.layer_growth_index.values()) >= max_time_window_growth_size
and sum(self.layer_growth_index.values())
>= max_time_window_growth_size
):
self.trigger_interval_growth_exceeded()

if not skip_sum_check and sum(self.layer_index.values()) >= max_cache_size:
if (
not skip_sum_check
and sum(self.layer_index.values()) >= max_cache_size
):
self.trigger_max_cache_size()

def trigger_layer_size_exceeded(self, layer_name: str):
Expand Down Expand Up @@ -323,7 +329,13 @@ def drop(self):


def main():
global watch_dir, large_layer_size, max_cache_size, time_window, max_time_window_growth_size, log_file_accessing_err
global \
watch_dir, \
large_layer_size, \
max_cache_size, \
time_window, \
max_time_window_growth_size, \
log_file_accessing_err

default_config_path = sys.argv[1] if len(sys.argv) > 1 else "default.conf"

Expand All @@ -336,7 +348,9 @@ def main():
log_file_accessing_err = True

if os.path.isfile(default_config_path):
logger.info(f"read config from {os.path.abspath(default_config_path)!r}")
logger.info(
f"read config from {os.path.abspath(default_config_path)!r}"
)

cfg = dotenv_values(default_config_path)

Expand All @@ -362,7 +376,9 @@ def main():
)
)
logger.info(
" ".join(["with `log_file_accessing_err` set to", log_file_accessing_err])
" ".join(
["with `log_file_accessing_err` set to", log_file_accessing_err]
)
)

# init watcher
Expand Down

0 comments on commit 8a28026

Please sign in to comment.