download

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(ctx context.Context, url string, outPath string, progressCh chan<- any, id string) error

Download is the CLI entry point (non-TUI) - convenience wrapper

func TUIDownload

func TUIDownload(ctx context.Context, cfg *types.DownloadConfig) error

TUIDownload is the main entry point for downloads executed by the Engine pool

Types

type WorkerPool

type WorkerPool struct {
	// contains filtered or unexported fields
}

WorkerPool manages the download workers and tasks.

Lock Ordering: If a code path must acquire both the pool's main mutex (p.mu) and a limiter's internal mutex (limiter.mu, via limiter.SetRate() or limiter.WaitN()), it MUST acquire p.mu first. Examples: Add, SetDownloadRateLimit, SetDefaultDownloadRateLimit. Never acquire p.mu while holding a limiter's internal mutex to prevent deadlocks.

func NewWorkerPool

func NewWorkerPool(progressCh chan<- any, maxDownloads int) *WorkerPool

func (*WorkerPool) ActiveCount

func (p *WorkerPool) ActiveCount() int

ActiveCount returns the number of currently active (downloading/pausing) downloads

func (*WorkerPool) Add

func (p *WorkerPool) Add(cfg types.DownloadConfig)

Add adds a new download task to the pool. The caller (LifecycleManager) is responsible for emitting any lifecycle events (e.g. DownloadQueuedMsg).

func (*WorkerPool) Cancel

func (p *WorkerPool) Cancel(downloadID string) types.CancelResult

Cancel cancels and removes a download by ID. Returns metadata about what was removed so the caller (LifecycleManager) can emit events and handle cleanup. No events are emitted by the pool itself.

func (*WorkerPool) ClearDownloadRateLimit added in v0.9.0

func (p *WorkerPool) ClearDownloadRateLimit(downloadID string) bool

ClearDownloadRateLimit removes a specific download's override so it inherits the current default.

func (*WorkerPool) ExtractPausedConfig added in v0.7.8

func (p *WorkerPool) ExtractPausedConfig(downloadID string) *types.DownloadConfig

ExtractPausedConfig atomically removes a paused download from the pool and returns its config (with state cleared for re-enqueue) so the LifecycleManager can resume it. Returns nil if the download is not found, not paused, or still transitioning (pausing).

func (*WorkerPool) GetAll

func (p *WorkerPool) GetAll() []types.DownloadConfig

GetAll returns all active download configs (for listing)

func (*WorkerPool) GetStatus

func (p *WorkerPool) GetStatus(id string) *types.DownloadStatus

GetStatus returns the status of an active download

func (*WorkerPool) GracefulShutdown

func (p *WorkerPool) GracefulShutdown()

GracefulShutdown pauses all downloads and waits for them to save state

func (*WorkerPool) HasDownload

func (p *WorkerPool) HasDownload(url string) bool

HasDownload reports whether a download with the given URL is currently active or queued in the pool.

func (*WorkerPool) Pause

func (p *WorkerPool) Pause(downloadID string) bool

Pause pauses a specific download by ID. Returns true if found and pause initiated (or already paused), false otherwise. Pure mechanical operation - no events emitted.

func (*WorkerPool) PauseAll

func (p *WorkerPool) PauseAll()

PauseAll pauses all active downloads (for graceful shutdown)

func (*WorkerPool) SetDefaultDownloadRateLimit added in v0.9.0

func (p *WorkerPool) SetDefaultDownloadRateLimit(rate int64)

SetDefaultDownloadRateLimit updates the default per-download rate limit (bytes/sec).

func (*WorkerPool) SetDownloadRateLimit added in v0.9.0

func (p *WorkerPool) SetDownloadRateLimit(downloadID string, rate int64) bool

SetDownloadRateLimit updates a specific download's rate limit (bytes/sec).

func (*WorkerPool) SetGlobalRateLimit added in v0.9.0

func (p *WorkerPool) SetGlobalRateLimit(rate int64)

SetGlobalRateLimit updates the global rate limiter (bytes/sec). Use 0 to disable.

func (*WorkerPool) UpdateURL

func (p *WorkerPool) UpdateURL(downloadID string, newURL string) error

UpdateURL updates the in-memory URL of a download by ID. The caller (LifecycleManager) is responsible for persisting the change to the DB. It fails if the download is actively downloading (not paused or errored).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL