Skip to content

Commit 330b921

Browse files
committed
add options to clean/expire using batches
1 parent a6933b2 commit 330b921

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cads_worker/entry_points.py

+13
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ class CleanerKwargs(TypedDict):
2929
lock_validity_period: float
3030
use_database: bool
3131
depth: int
32+
batch_size: int | None
33+
batch_sleep: int
3234

3335

3436
def _cache_cleaner() -> None:
3537
use_database = strtobool(os.environ.get("USE_DATABASE", "1"))
38+
batch_size = os.getenv("CACHE_BATCH_SLEEP")
3639
cleaner_kwargs = CleanerKwargs(
3740
maxsize=int(os.environ.get("MAX_SIZE", 1_000_000_000)),
3841
method=os.environ.get("METHOD", "LRU"),
3942
delete_unknown_files=not use_database,
4043
lock_validity_period=float(os.environ.get("LOCK_VALIDITY_PERIOD", 86400)),
4144
use_database=use_database,
4245
depth=int(os.getenv("CACHE_DEPTH", 2)),
46+
batch_size=batch_size if batch_size is None else int(batch_size),
47+
batch_sleep=int(os.getenv("CACHE_BATCH_SLEEP", 0)),
4348
)
4449
for cache_files_urlpath in utils.parse_data_volumes_config():
4550
cacholote.config.set(cache_files_urlpath=cache_files_urlpath)
@@ -77,6 +82,12 @@ def _expire_cache_entries(
7782
delete: Annotated[
7883
bool, Option("--delete", help="Delete entries to expire")
7984
] = False,
85+
batch_size: Annotated[
86+
int | None, Option(help="Group cache entries to expire into batches")
87+
] = None,
88+
batch_sleep: Annotated[
89+
int, Option(help="Sleep duration after processing each batch")
90+
] = 0,
8091
) -> int:
8192
"""Expire cache entries."""
8293
if (all_collections and collection_id) or not (all_collections or collection_id):
@@ -89,6 +100,8 @@ def _expire_cache_entries(
89100
before=_add_tzinfo(before),
90101
after=_add_tzinfo(after),
91102
delete=delete,
103+
batch_size=batch_size,
104+
batch_sleep=batch_sleep,
92105
)
93106
typer.echo(f"Number of entries expired: {count}")
94107
return count

0 commit comments

Comments
 (0)