Skip to content

feat(gallery/downloader): Implement Advanced Download Management System (Pause/Resume, Auto-Resume, Sidecar, and Throttling)#10478

Open
aslamalkarywk7 wants to merge 1 commit into
mudler:masterfrom
aslamalkarywk7:feat/download-management
Open

feat(gallery/downloader): Implement Advanced Download Management System (Pause/Resume, Auto-Resume, Sidecar, and Throttling)#10478
aslamalkarywk7 wants to merge 1 commit into
mudler:masterfrom
aslamalkarywk7:feat/download-management

Conversation

@aslamalkarywk7

Copy link
Copy Markdown

Description

This PR introduces a comprehensive, production-grade Download Management System for the model gallery downloader. It replaces the previous aggressive clean-up behavior (which deleted .partial files upon any cancellation) with an explicit pause/resume architecture, and layers four robust capabilities on top:

  1. Global Pause & Resume: Administrative endpoints (/api/operations/pause-all and /api/operations/resume-all) to pause or resume all active gallery operations concurrently.
  2. Download Metadata Sidecar (.partial.json): Safely marshals download state (original URL, timestamp, model ID) into a sidecar descriptor file when paused, protecting progress against application crashes or manual restarts.
  3. Auto-Resume on Boot: Scans the models directory upon service initialization (Start()), parses orphaned sidecar metadata, and auto-queues interrupted downloads using native HTTP Range headers.
  4. Dynamic Bandwidth Throttling: Implements a thread-safe token-bucket rate limiter around the core io.Reader wrapper, exposing a configurable API (/api/operations/:jobID/throttle?rate=2mb) supporting kb/mb/gb human-readable formats.

This PR fixes # (Leave blank or insert issue number if applicable)


Notes for Reviewers

  • Architecture: Leverages Go's structured context causes (context.WithCancelCause) via downloader.ErrUserPaused. This ensures that explicit pauses skip the asset erasure wrapper (removePartialFile), while traditional user cancels (ErrUserCancelled) maintain backward-compatible cleanup behaviors.
  • Modularity: Isolated the sidecar processing and token-bucket concurrency structures into dedicated files (pkg/downloader/sidecar.go and pkg/downloader/ratelimit.go) to adhere strictly to separation of concerns and maintain a clean uri.go.
  • Windows Integration Warning: Please note that pre-existing OS file-handle locks on Windows (os.Rename collisions) that historically fail standard cancel_test.go suites under NTFS remain downstream constraints. The underlying core logic has been tested cleanly and runs natively out-of-the-box on standard Linux/Docker runtime environments.

cc: @mudler for review when time permits.
Signed commits

  • Yes, I signed my commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant