From 368cf0a0976c8ff97d51300cfa61ea0b36472111 Mon Sep 17 00:00:00 2001 From: Squeaky Date: Mon, 16 Sep 2024 18:00:03 +0200 Subject: [PATCH] --fraction #notests --- bin/recompress-raw-mime.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/recompress-raw-mime.py b/bin/recompress-raw-mime.py index e667d11a7..bd8ce62b1 100755 --- a/bin/recompress-raw-mime.py +++ b/bin/recompress-raw-mime.py @@ -35,6 +35,7 @@ class Resolution(enum.Enum): NOT_PRESENT = "not-present" RECOMPRESS = "recompress" + SKIP = "skip" # https://stackoverflow.com/questions/73395864/how-do-i-wait-when-all-threadpoolexecutor-threads-are-busy @@ -264,6 +265,7 @@ def recompress_batch( @click.option( "--max-recompress-batch-bytes", type=int, default=MAX_RECOMPRESS_BATCH_BYTES ) +@click.option("--fraction", type=str, default=None) def run( limit: "int | None", after: "str | None", @@ -280,6 +282,7 @@ def run( compression_level: int, max_size: "int | None", max_recompress_batch_bytes: int, + fraction: "str | None", ) -> int: shutting_down = False @@ -292,6 +295,14 @@ def shutdown(signum, frame): signal.signal(signal.SIGINT, shutdown) signal.signal(signal.SIGTERM, shutdown) + fraction_tuple = None + if fraction is not None: + fraction_tuple = tuple(map(int, fraction.split("/"))) + assert len(fraction_tuple) == 2 + assert fraction_tuple[0] >= 0 + assert fraction_tuple[1] > 1 + assert fraction_tuple[0] < fraction_tuple[1] + assert batch_size > 0 assert recompress_batch_size > 0 @@ -328,6 +339,12 @@ def shutdown(signum, frame): else: resolution = Resolution.RECOMPRESS + if ( + fraction_tuple is not None + and message.id % fraction_tuple[1] != fraction_tuple[0] + ): + resolution = Resolution.SKIP + print_arguments = [ f"{message.id}/{max_id}", message.created_at.date(),