| 1 | pub fn poll_task(task_id: &str, base_url: &str, api_key: &str) { |
| 2 | loop { |
| 3 | let request = ureq::get(format!("{}/api/task/{}", base_url, task_id).as_str()) |
| 4 | .set("Content-Type", "application/json") |
| 5 | .set("Authorization", api_key) |
| 6 | .call() |
| 7 | .expect("Failed to send request"); |
| 8 | |
| 9 | let response: serde_json::Value = request.into_json().expect("Failed to parse response"); |
| 10 | |
| 11 | if response["status"] == "Completed" || response["status"] == "Failed" { |
| 12 | println!("{}", response); |
| 13 | break; |
| 14 | } else { |
| 15 | println!("Task is still processing..."); |
| 16 | println!("{}", response); |
| 17 | std::thread::sleep(std::time::Duration::from_secs(5)); |
| 18 | } |
| 19 | } |
| 20 | } |