Skip to content

Commit

Permalink
retry retryable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sesi200 committed Dec 22, 2023
1 parent 4b804bb commit 9147059
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/dfx/src/lib/ic_attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ic_utils::interfaces::management_canister::attributes::{
};
use std::convert::TryFrom;

#[derive(Default, Debug)]
#[derive(Default, Debug, Clone)]
pub struct CanisterSettings {
pub controllers: Option<Vec<Principal>>,
pub compute_allocation: Option<ComputeAllocation>,
Expand Down
45 changes: 28 additions & 17 deletions src/dfx/src/lib/operations/cycles_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,34 @@ pub async fn create_with_cycles_ledger(
Some(now)
});

let result = agent
.update(&cycles_ledger_canister_id, CREATE_CANISTER_METHOD)
.with_arg(
Encode!(&CreateCanisterArgs {
from_subaccount,
created_at_time,
amount: cycles,
creation_args: Some(CmcCreateCanisterArgs {
settings: Some(settings.into()),
subnet_selection: None,
}),
})
.unwrap(),
)
.call_and_wait()
.await
.map_err(|err| anyhow!(err))?;
let result = loop {
match agent
.update(&cycles_ledger_canister_id, CREATE_CANISTER_METHOD)
.with_arg(
Encode!(&CreateCanisterArgs {
from_subaccount,
created_at_time,
amount: cycles,
creation_args: Some(CmcCreateCanisterArgs {
settings: Some(settings.clone().into()),
subnet_selection: None,
}),
})
.unwrap(),
)
.call_and_wait()
.await
{
Ok(result) => break result,
Err(err) => {
if retryable(&err) {
info!(env.get_logger(), "Request error: {err:?}. Retrying...");
} else {
bail!(err)
}
}
}
};
let create_result = Decode!(
&result,
Result<CreateCanisterSuccess, CreateCanisterError>
Expand Down

0 comments on commit 9147059

Please sign in to comment.