From 9fc1378af1453cf765840976d7b4528e09341624 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Thu, 31 Oct 2024 17:03:58 -0500 Subject: [PATCH] Refactor Scheduler parameters --- netkan/netkan/cli/services.py | 19 ++++++++++++------- netkan/netkan/scheduler.py | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/netkan/netkan/cli/services.py b/netkan/netkan/cli/services.py index 3749965..76514a0 100644 --- a/netkan/netkan/cli/services.py +++ b/netkan/netkan/cli/services.py @@ -22,15 +22,15 @@ def indexer(common: SharedArgs) -> None: @click.command(short_help='The Scheduler service') -@click.option( - '--max-queued', default=20, envvar='MAX_QUEUED', - help='SQS Queue to send netkan metadata for scheduling', -) @click.option( '--group', type=click.Choice(['all', 'webhooks', 'nonhooks']), default="nonhooks", help='Which mods to schedule', ) +@click.option( + '--max-queued', default=20, envvar='MAX_QUEUED', + help='Only schedule if the inflation queue already has fewer than this many messages', +) @click.option( '--min-cpu', default=200, help='Only schedule if we have at least this many CPU credits remaining', @@ -39,14 +39,19 @@ def indexer(common: SharedArgs) -> None: '--min-io', default=70, help='Only schedule if we have at least this many IO credits remaining', ) +@click.option( + '--min-gh', default=1500, + help='Only schedule if our GitHub API rate limit has this many remaining', +) @common_options @pass_state def scheduler( common: SharedArgs, - max_queued: int, group: str, + max_queued: int, min_cpu: int, - min_io: int + min_io: int, + min_gh: int ) -> None: """ Reads netkans from a NetKAN repo and submits them to the @@ -59,7 +64,7 @@ def scheduler( nonhooks_group=(group in ('all', 'nonhooks')), webhooks_group=(group in ('all', 'webhooks')), ) - if sched.can_schedule(max_queued, common.dev, min_cpu, min_io): + if sched.can_schedule(max_queued, min_cpu, min_io, min_gh, common.dev): sched.schedule_all_netkans() logging.info("NetKANs submitted to %s", game.inflation_queue) diff --git a/netkan/netkan/scheduler.py b/netkan/netkan/scheduler.py index 35d1c54..8e90cf5 100644 --- a/netkan/netkan/scheduler.py +++ b/netkan/netkan/scheduler.py @@ -110,8 +110,8 @@ def volume_credits_percent(cloudwatch: CloudWatchClient, instance_id: str, logging.error("Couldn't acquire Volume Credit Stats") return creds - def can_schedule(self, max_queued: int, dev: bool = False, - min_cpu: int = 50, min_io: int = 70, min_gh: int = 1500) -> bool: + def can_schedule(self, max_queued: int, min_cpu: int, min_io: int, min_gh: int, + dev: bool = False) -> bool: if not dev: github_remaining = github_limit_remaining(self.github_token) if github_remaining < min_gh: