Skip to content

Draft: Download manager #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dbbe919
chore: Add reqwest crate
cyberphantom52 Jul 20, 2025
748106a
downloader: Implement DownloadManager
cyberphantom52 Jul 20, 2025
c5479b8
error: Add reqwest errors
cyberphantom52 Jul 20, 2025
9c29890
downloader: Propagate errors and correctly update download status
cyberphantom52 Jul 20, 2025
ad41c23
downloader: Implement cancelling downloads
cyberphantom52 Jul 20, 2025
447be8e
downloader: Implement retries
cyberphantom52 Jul 20, 2025
395ced4
downloader: Improve File handling and use switch to tokio::fs::File
cyberphantom52 Jul 20, 2025
1bf7bfd
downloader: Use tokio::select to check for cancellations
cyberphantom52 Jul 20, 2025
9adb239
downloader: Send initial progress update and return error for response
cyberphantom52 Jul 20, 2025
b9911b8
downloader: Implement Future trait for DownloadHandle
cyberphantom52 Jul 20, 2025
9f25867
downloader: End progress updates at completion too
cyberphantom52 Jul 20, 2025
c313200
downloader: Manually drop file handle before deleting on error or cancel
cyberphantom52 Jul 20, 2025
926d2fc
fix: gptk impl
edfloreshz Jul 21, 2025
3fe1e92
downloader: Refactor retry logic and improve errors
cyberphantom52 Jul 21, 2025
49d4f60
downloader: Add method to wait for status updates
cyberphantom52 Jul 21, 2025
7973137
downloader: fix retry logic
cyberphantom52 Jul 21, 2025
31f5218
downloader: Use tokio_util::CancellationToken to handle cancellations
cyberphantom52 Jul 21, 2025
d96688d
downloader: Add hierarchical cancel tokens to cancel all downloads
cyberphantom52 Jul 21, 2025
3a14a0d
downloader: Split the implementation into a module
cyberphantom52 Jul 23, 2025
5566d67
downloader: Add better progress updates with rate limiting
cyberphantom52 Jul 23, 2025
2aac716
downloader: Better download interface with errors
cyberphantom52 Jul 23, 2025
9251524
downloader: Add some convinience methods related to download status
cyberphantom52 Jul 23, 2025
0670468
downloader: Add config for download manager
cyberphantom52 Jul 23, 2025
ce05710
downloader: Use TaskTracker to track thread lifecycles
cyberphantom52 Jul 23, 2025
633b752
downloader: Add shutdown, active_downloads and queued_downloads
cyberphantom52 Jul 23, 2025
09b47b6
downloader: Add DownloadConfig and rate limiting
cyberphantom52 Jul 23, 2025
4803c51
downloader: Use builder pattern to build download requests
cyberphantom52 Jul 23, 2025
9e9b298
downloader: Don't rexport worker_thread
cyberphantom52 Jul 23, 2025
987beaa
downloader: Switch to url::Url
cyberphantom52 Jul 23, 2025
c550480
downloader: Accept Url's directly instead of parsing them
cyberphantom52 Jul 23, 2025
8354cc9
downloader: Add convinience methods to send updates and result
cyberphantom52 Jul 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,24 @@ pub struct DownloadHandle {
cancel: oneshot::Sender<()>,
}

impl DownloadHandle {
pub async fn r#await(self) -> Result<File, Error> {
match self.result.await {
Ok(result) => result,
Err(_) => todo!(),
impl std::future::Future for DownloadHandle {
type Output = Result<tokio::fs::File, Error>;

fn poll(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
use std::pin::Pin;
use std::task::Poll;
match Pin::new(&mut self.result).poll(cx) {
Poll::Ready(Ok(result)) => Poll::Ready(result),
Poll::Ready(Err(e)) => Poll::Ready(Err(Error::Oneshot(e))),
Poll::Pending => Poll::Pending,
}
}
}

impl DownloadHandle {
pub fn status(&self) -> Status {
self.status.borrow().clone()
}
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ pub enum Error {
Serde(#[from] serde_json::Error),
#[error("Reqwest: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("Oneshot: {0}")]
Oneshot(#[from] tokio::sync::oneshot::error::RecvError),
Comment on lines +12 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having to add this specific error type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, not sure, RecvError could map to a more general channel cancellation variant instead of adding a dedicated Oneshot error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can add anyhow crate and don't have to worry about this

}