diff --git a/src/asvo/asvo_serde.rs b/src/asvo/asvo_serde.rs index c75bb60..b856468 100644 --- a/src/asvo/asvo_serde.rs +++ b/src/asvo/asvo_serde.rs @@ -62,9 +62,13 @@ impl DummyJob { let mut file_array = vec![]; for dumb_product in &hm["files"] { file_array.push(AsvoFilesArray { - r#type: dumb_product.r#type.clone(), + r#type: match dumb_product.r#type.as_str() { + "acacia" => Delivery::Acacia, + "astro" => Delivery::Astro, + _ => panic!("Unsupported file type found.") + }, url: dumb_product.url.clone(), - path: None, + path: dumb_product.r#path.clone(), size: dumb_product.size, sha1: dumb_product.sha1.clone(), }) diff --git a/src/asvo/error.rs b/src/asvo/error.rs index b940029..1d1c462 100644 --- a/src/asvo/error.rs +++ b/src/asvo/error.rs @@ -122,4 +122,8 @@ pub enum AsvoError { // Error determining path for Astro job #[error("Could not determine path for job {job_id:?}")] NoPath { job_id: u32 }, + + // Error determining path for Astro job + #[error("Invalid file type for job {job_id:?}")] + InvalidFileType { job_id: u32 }, } diff --git a/src/asvo/mod.rs b/src/asvo/mod.rs index 556e93f..862ca73 100644 --- a/src/asvo/mod.rs +++ b/src/asvo/mod.rs @@ -182,11 +182,12 @@ impl AsvoClient { bytesize::ByteSize(total_bytes).to_string_as(true) ); let start_time = Instant::now(); + // Download each file. for f in files { - match f.r#type.as_str() { - "acacia" => { + match f.r#type { + Delivery::Acacia => { match f.url.as_deref() { Some(url) => { debug!("Downloading file {:?}", f.url); @@ -254,6 +255,21 @@ impl AsvoClient { } } } + + info!( + "Completed download in {} (average rate: {}/s)", + if start_time.elapsed().as_secs() > 60 { + format!( + "{}min{:.2}s", + start_time.elapsed().as_secs() / 60, + (start_time.elapsed().as_millis() as f64 / 1e3) % 60.0 + ) + } else { + format!("{}s", start_time.elapsed().as_millis() as f64 / 1e3) + }, + bytesize::ByteSize((total_bytes as u128 * 1000 / start_time.elapsed().as_millis()) as u64) + .to_string_as(true) + ); }, None => { return Err(AsvoError::NoUrl { @@ -262,14 +278,15 @@ impl AsvoClient { } } }, - "astro" => { - match f.path.as_deref() { + Delivery::Astro => { + match &f.path { Some(path) => { - let path_obj = Path::new(path); + //If it's an /astro job, and the files are reachable from the current host, move them into the current working directory + let path_obj = Path::new(&path); let folder_name = path_obj.components().last().unwrap().as_os_str().to_str().unwrap(); if !Path::exists(path_obj) { - info!("Files for Astro Job {} are not reachable from the current host.", job.jobid) + info!("Files for Astro Job {} are not reachable from the current host.", job.jobid); } else { info!("Files for Astro Job {} are reachable from the current host. Copying to current directory.", job.jobid); @@ -284,27 +301,10 @@ impl AsvoClient { }) } } - }, - _ => panic!("Unsuppored file type found") + } } } - let d = Instant::now() - start_time; - info!( - "Completed download in {} (average rate: {}/s)", - if d.as_secs() > 60 { - format!( - "{}min{:.2}s", - d.as_secs() / 60, - (d.as_millis() as f64 / 1e3) % 60.0 - ) - } else { - format!("{}s", d.as_millis() as f64 / 1e3) - }, - bytesize::ByteSize((total_bytes as u128 * 1000 / d.as_millis()) as u64) - .to_string_as(true) - ); - Ok(()) } diff --git a/src/asvo/types.rs b/src/asvo/types.rs index ddb41dc..b57ce2e 100644 --- a/src/asvo/types.rs +++ b/src/asvo/types.rs @@ -68,7 +68,7 @@ impl FromStr for AsvoJobState { #[derive(Serialize, PartialEq, Debug)] pub struct AsvoFilesArray { #[serde(rename = "jobType")] - pub r#type: String, + pub r#type: Delivery, #[serde(rename = "fileUrl")] pub url: Option, #[serde(rename = "filePath")] @@ -246,7 +246,7 @@ impl std::fmt::Display for AsvoJob { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq, Debug, Serialize)] pub enum Delivery { /// "Deliver" the ASVO job to "the cloud" so it can be downloaded from /// anywhere.