Skip to content

Commit 72dc22b

Browse files
authored
add options to clean/expire using batches (#53)
* add options to clean/expire using batches * fix envvar * change varnames * add --dry-run * use partitions * apply to expire only * sync with cacholote * cleanup * cleanup * cleanup * cleanup * cleanup * cleanup * restore flags * dry run flag * better help
1 parent 66d7f54 commit 72dc22b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Diff for: cads_worker/entry_points.py

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

3335

3436
def _cache_cleaner() -> None:
@@ -40,6 +42,8 @@ def _cache_cleaner() -> None:
4042
lock_validity_period=float(os.environ.get("LOCK_VALIDITY_PERIOD", 86400)),
4143
use_database=use_database,
4244
depth=int(os.getenv("CACHE_DEPTH", 2)),
45+
batch_size=int(os.getenv("BATCH_SIZE", 0)) or None,
46+
batch_delay=float(os.getenv("BATCH_DELAY", 0)),
4347
)
4448
for cache_files_urlpath in utils.parse_data_volumes_config():
4549
cacholote.config.set(cache_files_urlpath=cache_files_urlpath)
@@ -77,6 +81,20 @@ def _expire_cache_entries(
7781
delete: Annotated[
7882
bool, Option("--delete", help="Delete entries to expire")
7983
] = False,
84+
batch_size: Annotated[
85+
int | None,
86+
Option(help="Number of entries to process in each batch"),
87+
] = None,
88+
batch_delay: Annotated[
89+
float,
90+
Option(
91+
help="Delay in seconds between processing batches",
92+
),
93+
] = 0,
94+
dry_run: Annotated[
95+
bool,
96+
Option("--dry-run", help="Perform a trial run that doesn't make any changes"),
97+
] = False,
8098
) -> int:
8199
"""Expire cache entries."""
82100
if (all_collections and collection_id) or not (all_collections or collection_id):
@@ -89,8 +107,11 @@ def _expire_cache_entries(
89107
before=_add_tzinfo(before),
90108
after=_add_tzinfo(after),
91109
delete=delete,
110+
batch_size=batch_size,
111+
batch_delay=batch_delay,
112+
dry_run=dry_run,
92113
)
93-
typer.echo(f"Number of entries expired: {count}")
114+
typer.echo(f"Number of entries {'to expire' if dry_run else 'expired'}: {count}")
94115
return count
95116

96117

0 commit comments

Comments
 (0)