/// Installs this wasm onto the given pre-existing canister, with
/// retries.This is especially useful when the runtime is remote, and
/// for which transient errors may happen.
Installs this wasm onto the given pre-existing canister, with
retries.This is especially useful when the runtime is remote, and
for which transient errors may happen.
Installs this wasm onto the given pre - existing canister with retries . This is especially useful when the runtime is remote and for which transient errors may happen .
pub async fn install_with_retries_onto_canister(
        self,
        mut canister: &mut Canister<'_>,
        canister_init_payload: Option<Vec<u8>>,
        memory_allocation: Option<u64>,
    ) -> Result<(), String> {
        let init_payload = canister_init_payload.unwrap_or_default();
        let runtime = canister.runtime;
        let mut backoff = get_backoff_policy();
        loop {
            let mut install = self
                .clone()
                .install(runtime)
                .with_mode(CanisterInstallMode::Reinstall);
            if let Some(memory_allocation) = memory_allocation {
                install = install.with_memory_allocation(memory_allocation);
            }
            let canister_id = canister.canister_id;
            println!(
                "Attempting to install wasm into canister with ID: {}",
                canister_id
            );
            match install.install(&mut canister, init_payload.clone()).await {
                Ok(()) => {
                    println!(
                        "Successfully installed wasm into canister with ID: {}",
                        canister_id
                    );
                    return Ok(());
                }
                Err(e) => {
                    eprintln!(
                        "Installation of wasm into cansiter with ID: {} failed with: {}",
                        canister_id, e
                    );
                    match backoff.next_backoff() {
                        Some(interval) => {
                            std::thread::sleep(interval);
                        }
                        None => {
                            return Err(format!(
                                "Canister installation timed out. Last error was: {}",
                                e
                            ));
                        }
                    }
                }
            }
        }
    }
pub async fn install_with_retries_onto_canister ( self , mut canister : & mut Canister < ' _ > , canister_init_payload : Option < Vec < u8 > > , memory_allocation : Option < u64 > , ) -> Result < ( ) , String > { let init_payload = canister_init_payload . unwrap_or_default ( ) ; let runtime = canister . runtime ; let mut backoff = get_backoff_policy ( ) ; loop { let mut install = self . clone ( ) . install ( runtime ) . with_mode ( CanisterInstallMode :: Reinstall ) ; if let Some ( memory_allocation ) = memory_allocation { install = install . with_memory_allocation ( memory_allocation ) ; } let canister_id = canister . canister_id ; println ! ( " " canister_id ) ; match install . install ( & mut canister , init_payload . clone ( ) ) . await { Ok ( ( ) ) => { println ! ( " " canister_id ) ; return Ok ( ( ) ) ; } Err ( e ) => { eprintln ! ( " " canister_id e ) ; match backoff . next_backoff ( ) { Some ( interval ) => { std :: thread :: sleep ( interval ) ; } None => { return Err ( format ! ( " " e ) ) ; } } } } } }
Installs this wasm onto the given pre-existing canister, with
retries.This is especially useful when the runtime is remote, and
for which transient errors may happen.
Installs this wasm onto the given pre - existing canister with retries . This is especially useful when the runtime is remote and for which transient errors may happen .
self
canister
&mut Canister<'_>
canister_init_payload
Option<Vec<u8>>
memory_allocation
Option<u64>