Skip to content

Commit

Permalink
Monitor subsequent cloud operations (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsidnev authored Oct 11, 2023
1 parent c97cd8b commit 1d9c1cb
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/cloud/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub struct CloudOperation {
pub status: OperationStatus,
pub description: String,
pub message: String,
pub subsequent_id: Option<String>,
}

#[tokio::main]
Expand Down Expand Up @@ -170,19 +171,32 @@ async fn wait_for_operation(
.with_message(format!("Monitoring {}...", operation.description));
spinner.enable_steady_tick(SPINNER_TICK);

let url = format!("operations/{}", operation.id);
let mut url = format!("operations/{}", operation.id);
let deadline = Instant::now() + OPERATION_WAIT_TIME;

let mut original_error = None;

while Instant::now() < deadline {
match operation.status {
OperationStatus::Failed => {
anyhow::bail!(operation.message);
match (operation.status, operation.subsequent_id) {
(OperationStatus::Failed, Some(subsequent_id)) => {
original_error = original_error.or(Some(operation.message));

url = format!("operations/{}", subsequent_id);
operation = client.get(&url).await?;
},
(OperationStatus::Failed, None) => {
anyhow::bail!(original_error.unwrap_or(operation.message));
},
OperationStatus::InProgress => {
(OperationStatus::InProgress, _) => {
sleep(POLLING_INTERVAL).await;
operation = client.get(&url).await?;
}
OperationStatus::Completed => {
return Ok(());
(OperationStatus::Completed, _) => {
if let Some(message) = original_error {
anyhow::bail!(message)
} else {
return Ok(())
}
}
}
}
Expand Down

0 comments on commit 1d9c1cb

Please sign in to comment.