Skip to content

Commit

Permalink
Error handling, change to astro jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisonbarlow committed Jul 7, 2022
1 parent dce3dfa commit fd48acf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
8 changes: 6 additions & 2 deletions src/asvo/asvo_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
Expand Down
4 changes: 4 additions & 0 deletions src/asvo/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
48 changes: 24 additions & 24 deletions src/asvo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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);

Expand All @@ -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(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/asvo/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[serde(rename = "filePath")]
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fd48acf

Please sign in to comment.