Skip to main content

DownloadEngine

Struct DownloadEngine 

Source
pub struct DownloadEngine { /* private fields */ }
Expand description

Coordinates the task lifecycle: resolving links, adding and running tasks, pausing, resuming, cancelling and requeueing tasks left behind by a crashed process.

Implementations§

Source§

impl DownloadEngine

Source

pub fn new( router: Arc<Router>, store: Arc<dyn TaskStore>, config: Config, ) -> Self

Creates an engine over the given router, task store and configuration. Subscribe with DownloadEngine::subscribe before adding tasks to observe their events.

Source

pub fn with_telemetry(self, telemetry: Arc<dyn Telemetry>) -> Self

Replaces the no-op telemetry sink. Builder form; use DownloadEngine::set_telemetry to change it after construction.

Source

pub fn set_telemetry(&mut self, telemetry: Arc<dyn Telemetry>)

Replaces the telemetry sink used for subsequent tasks.

Source

pub fn telemetry(&self) -> &Arc<dyn Telemetry> ⓘ

Returns the installed telemetry sink.

Source

pub fn with_finalizers(self, finalizers: FinalizerPipeline) -> Self

Replaces the post-download finalizer pipeline. The default verifies checksums and extracts archives.

Source

pub fn set_finalizers(&mut self, finalizers: FinalizerPipeline)

Replaces the finalizer pipeline used for subsequent tasks.

Source

pub fn subscribe(&self) -> Receiver<DownloadEvent>

Subscribes to the engine’s event stream. Only events emitted after the call are received.

Source

pub fn config(&self) -> &Config

Returns the configuration used to resolve task options.

Source

pub fn events(&self) -> &EventSink

Returns the event sink backends use to report progress.

Source

pub fn store(&self) -> &Arc<dyn TaskStore> ⓘ

Returns the task store backing the engine.

Source

pub async fn resolve( &self, link: &Link, options: &ParseOptions, ) -> Result<RoutedResource>

Parses link and selects a backend without creating a task.

Source

pub async fn add( &self, link: Link, destination: PathBuf, options: TaskOptions, ) -> Result<Task>

Resolves link and persists a new pending task.

Unless TaskOptions::force is set, an active (pending, running or paused) task with the same canonical link and destination is returned instead of creating a duplicate.

Source

pub async fn run_task(&self, id: TaskId) -> Result<Task>

Runs a task to a terminal state without an external cancellation token.

Source

pub async fn run_task_with_cancel( &self, id: TaskId, external_cancel: Option<CancellationToken>, ) -> Result<Task>

Runs a task, optionally linked to an external cancellation token.

A task that is already completed is returned unchanged, while running a cancelled task is an error. A pause or cancel requested through the store (for example by another process) is observed while the transfer runs and stops it.

Source

pub async fn run_pending( &self, jobs: usize, cancel: CancellationToken, ) -> Result<Vec<Task>>

Runs every task currently in Pending state, at most jobs at a time (jobs is clamped to at least one). Higher-priority tasks are selected first, then older tasks. All tasks share cancel; tasks whose run fails are omitted from the returned list.

Source

pub async fn requeue_stale(&self) -> Result<Vec<TaskId>>

A previous process may have left tasks in running. The CLI calls this only while holding the single-worker lock.

Source

pub async fn pause(&self, id: TaskId) -> Result<Task>

Marks a task paused and cancels its in-flight transfer, if any. It can later be restarted with DownloadEngine::resume or run_task; pausing a completed task is an error.

Source

pub async fn cancel(&self, id: TaskId) -> Result<Task>

Marks a task cancelled and cancels its in-flight transfer, if any. A cancelled task is not restarted by DownloadEngine::run_task; use DownloadEngine::resume to move it back to pending. Cancelling an already completed task is an error.

Source

pub async fn resume(&self, id: TaskId) -> Result<Task>

Moves a task back to Pending and clears its error so the next run retries it, reusing any saved resume manifest. Resuming an already completed task is an error.

Source

pub async fn list(&self) -> Result<Vec<Task>>

Returns all tasks known to the store, oldest first.

Source

pub async fn status(&self, id: TaskId) -> Result<Task>

Loads a single task by id.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more