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
impl DownloadEngine
Sourcepub fn new(
router: Arc<Router>,
store: Arc<dyn TaskStore>,
config: Config,
) -> Self
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.
Sourcepub fn with_telemetry(self, telemetry: Arc<dyn Telemetry>) -> Self
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.
Sourcepub fn set_telemetry(&mut self, telemetry: Arc<dyn Telemetry>)
pub fn set_telemetry(&mut self, telemetry: Arc<dyn Telemetry>)
Replaces the telemetry sink used for subsequent tasks.
Sourcepub fn with_finalizers(self, finalizers: FinalizerPipeline) -> Self
pub fn with_finalizers(self, finalizers: FinalizerPipeline) -> Self
Replaces the post-download finalizer pipeline. The default verifies checksums and extracts archives.
Sourcepub fn set_finalizers(&mut self, finalizers: FinalizerPipeline)
pub fn set_finalizers(&mut self, finalizers: FinalizerPipeline)
Replaces the finalizer pipeline used for subsequent tasks.
Sourcepub fn subscribe(&self) -> Receiver<DownloadEvent>
pub fn subscribe(&self) -> Receiver<DownloadEvent>
Subscribes to the engine’s event stream. Only events emitted after the call are received.
Sourcepub async fn resolve(
&self,
link: &Link,
options: &ParseOptions,
) -> Result<RoutedResource>
pub async fn resolve( &self, link: &Link, options: &ParseOptions, ) -> Result<RoutedResource>
Parses link and selects a backend without creating a task.
Sourcepub async fn add(
&self,
link: Link,
destination: PathBuf,
options: TaskOptions,
) -> Result<Task>
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.
Sourcepub async fn run_task(&self, id: TaskId) -> Result<Task>
pub async fn run_task(&self, id: TaskId) -> Result<Task>
Runs a task to a terminal state without an external cancellation token.
Sourcepub async fn run_task_with_cancel(
&self,
id: TaskId,
external_cancel: Option<CancellationToken>,
) -> Result<Task>
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.
Sourcepub async fn run_pending(
&self,
jobs: usize,
cancel: CancellationToken,
) -> Result<Vec<Task>>
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.
Sourcepub async fn requeue_stale(&self) -> Result<Vec<TaskId>>
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.
Sourcepub async fn pause(&self, id: TaskId) -> Result<Task>
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.
Sourcepub async fn cancel(&self, id: TaskId) -> Result<Task>
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.
Sourcepub async fn resume(&self, id: TaskId) -> Result<Task>
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.