Skip to content

Commit

Permalink
--fraction #notests
Browse files Browse the repository at this point in the history
  • Loading branch information
squeaky-pl committed Oct 1, 2024
1 parent 0bb4157 commit 368cf0a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bin/recompress-raw-mime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 368cf0a

Please sign in to comment.