pub struct DownloadWorker {
client: Client,
max_retries: u32,
}Expand description
Download worker that handles individual download tasks
Fields§
§client: ClientHTTP client for downloads
max_retries: u32Maximum retry attempts
Implementations§
Source§impl DownloadWorker
impl DownloadWorker
pub fn new() -> Self
Sourcefn with_stall_timeout(stall: Duration, https_only: bool) -> Self
fn with_stall_timeout(stall: Duration, https_only: bool) -> Self
Build a worker whose HTTP client gives up on a transfer that receives
nothing for stall. https_only is relaxed only by tests, which serve
from a loopback socket.
The timeouts are a connect timeout and a read timeout — never
Client::timeout. That one is a total deadline that runs until the body
has finished, and it was set to five minutes: every download longer than
that was cut off mid-body with “error decoding response body”, then
retried. A transcode ignores Range, so each retry restarted from byte
zero, ran into the same five minutes, and after three attempts the
download failed — which is why no feature film at transcode speed ever
completed on a device that needs the audio re-encoded. A read timeout
resets on every chunk, so it catches a dead connection without putting a
ceiling on how long a healthy transfer may run.
TRACES: UR-071 | DR-289 | UT-251
Sourcepub async fn download<F>(
&self,
task: &DownloadTask,
stop: &AtomicBool,
on_progress: F,
) -> Result<DownloadResult, DownloadError>
pub async fn download<F>( &self, task: &DownloadTask, stop: &AtomicBool, on_progress: F, ) -> Result<DownloadResult, DownloadError>
Download a file with retry logic and progress tracking.
stop is the pause/cancel flag (see crate::download::stop). It is
checked between chunks and again between retries, so a paused download
stops promptly rather than after its next backoff — up to 45 seconds
away, which reads as the pause having done nothing.
TRACES: UR-055 | DR-168
Sourceasync fn try_download<F>(
&self,
task: &DownloadTask,
stop: &AtomicBool,
on_progress: &F,
) -> Result<DownloadResult, DownloadError>
async fn try_download<F>( &self, task: &DownloadTask, stop: &AtomicBool, on_progress: &F, ) -> Result<DownloadResult, DownloadError>
Attempt a single download
Sourcefn exponential_backoff(retry_count: u32) -> Duration
fn exponential_backoff(retry_count: u32) -> Duration
Calculate exponential backoff delay