feat(daemon): download scheduling windows and bandwidth throttling - #56
Open
rfsbraz wants to merge 1 commit into
Open
feat(daemon): download scheduling windows and bandwidth throttling#56rfsbraz wants to merge 1 commit into
rfsbraz wants to merge 1 commit into
Conversation
Contributor
Testing this PROption 1 — Docker Compose override: Create a services:
telegram-downloader:
build: https://github.com/rfsbraz/telegram-downloader.git#refs/pull/56/headThen run: docker compose up --buildOption 2 — Direct build and run: docker build https://github.com/rfsbraz/telegram-downloader.git#refs/pull/56/head -t telegram-downloader:pr-56
docker run --rm -it telegram-downloader:pr-56 |
There was a problem hiding this comment.
Pull request overview
This PR adds two user-configurable controls to the daemon: (1) scheduling windows that gate when a daemon check can start, and (2) an optional aggregate bandwidth cap applied during downloads via a shared async rate limiter.
Changes:
- Introduces
TDL_SCHEDULE_ACTIVE_HOURSparsing + daemon gating to skip checks outside configured time windows. - Introduces
TDL_MAX_DOWNLOAD_SPEEDparsing + a shared async token-bucket limiter wired into Pyrogram download progress. - Adds unit tests and README documentation for both settings, plus startup validation in config schema.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/daemon/test_schedule.py | Adds unit tests for active-hours parsing, cross-midnight behavior, and daemon check gating. |
| tests/unit/daemon/init.py | Marks daemon unit test package. |
| tests/unit/client/test_ratelimit.py | Adds unit tests for rate parsing and RateLimiter throttling behavior. |
| src/main.py | Wires optional RateLimiter into download flows and passes schedule config into DaemonService. |
| src/daemon/service.py | Adds active_hours configuration and gates run_check() based on parsed schedule windows. |
| src/daemon/schedule.py | Implements active-hours parsing and “within window” checks (including cross-midnight). |
| src/config/schema.py | Adds schedule_active_hours and max_download_speed config fields with startup validation. |
| src/config/loader.py | Allows the new config keys to be loaded from environment variables. |
| src/client/ratelimit.py | Implements parse_rate() and an async shared token-bucket RateLimiter. |
| src/client/downloader.py | Hooks the optional limiter into progress callbacks by feeding byte deltas to the limiter. |
| README.md | Documents scheduling and bandwidth environment variables and expected formats. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| limiter = None | ||
| if cfg.max_download_speed: | ||
| limiter = RateLimiter(parse_rate(cfg.max_download_speed)) | ||
| log.info(f"Download speed capped at {cfg.max_download_speed}/s") |
| "GB": 1024 ** 3, | ||
| } | ||
|
|
||
| _RATE_RE = re.compile(r"^([\d.]+)\s*([A-Z]+)?(?:/S)?$") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #36
TDL_SCHEDULE_ACTIVE_HOURSsetting gates daemon checks to configured time windows (24h local time via TZ); supports multiple comma-separated windows and windows that cross midnight (23:00-06:00)TDL_MAX_DOWNLOAD_SPEEDsetting (e.g.5MB) caps aggregate download speed via a shared async token-bucket limiter fed by pyrogram's progress callbacks, so throttling never blocks the event loop