feat(dl): add --speed-limit and serve global_speed_limit

Shared token bucket across all download threads; decimal suffixes (5M = 5.0 MB/s) or plain bytes/sec
This commit is contained in:
imSp4rky
2026-07-31 12:48:46 -06:00
parent e9a40a3af3
commit 734df87bad
9 changed files with 313 additions and 10 deletions
+9
View File
@@ -10,6 +10,7 @@ from unshackle.core.api import cors_middleware, setup_routes, setup_swagger
from unshackle.core.api.compression import compression_middleware
from unshackle.core.config import config
from unshackle.core.constants import context_settings
from unshackle.core.downloaders import format_speed, parse_speed_limit, set_speed_limit
@click.command(
@@ -146,6 +147,14 @@ def serve(
if remote_only:
api_only = True
try:
global_speed_limit = parse_speed_limit(config.serve.get("global_speed_limit"))
except ValueError as e:
raise click.ClickException(f"serve.global_speed_limit: {e}")
if global_speed_limit:
set_speed_limit(global_speed_limit, lock=True)
log.info(f"Global speed limit: {format_speed(global_speed_limit)} (shared by all jobs)")
global_services = config.serve.get("services")
if global_services:
log.info(f"Global service allowlist: {', '.join(global_services)}")