/
simple.rs
70 lines (59 loc) · 1.94 KB
/
simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! This binary crate demonstrates the use of the RING API client.
use std::env;
use std::thread;
use std::fmt::Debug;
use std::time::Duration;
use ring_api::{
client::Client,
requests::*,
job::*,
settings::*,
};
fn main() -> Result<(), Box<dyn Debug + 'static>> {
// Parse command-line arguments
let mut args: Vec<_> = env::args().collect();
let err_msg = "usage: simple [id | file] PDB_ID_OR_FILE_NAME";
let client = Client::new();
if args.len() != 3 {
return Err(Box::new(err_msg));
}
// Submit either a PDB ID or a PDB file
let submit_resp = match args[1].as_str() {
"id" => {
let req = SubmitId {
pdb_id: args.remove(2),
settings: Settings::default(),
};
client.send(req).map_err(|e| Box::new(e) as _)?
}
"file" => {
let req = SubmitStructure::with_pdb_file(&args[2])
.map_err(|e| Box::new(e) as _)?;
client.send(req).map_err(|e| Box::new(e) as _)?
}
_ => return Err(Box::new(err_msg)),
};
println!("Submitted; response = {:#?}", submit_resp);
// Wait for the result to be ready; poll status endpoint
loop {
let req = Status {
job_id: submit_resp.job_id.clone()
};
let status_resp = client.send(req).map_err(|e| Box::new(e) as _)?;
println!("Job ID: {}, status: {}", status_resp.job_id, status_resp.status);
match status_resp.status {
JobStatus::Failed => return Err(Box::new(
format!("Job failed: {:#?}", status_resp)
)),
JobStatus::Complete => break,
_ => thread::sleep(Duration::from_secs(5)),
}
}
// Retrieve results
let req = RetrieveResult {
job_id: submit_resp.job_id.clone()
};
let result_resp = client.send(req).map_err(|e| Box::new(e) as _)?;
println!("{:#?}", result_resp);
Ok(())
}