Skip to content

Commit

Permalink
Handle retry attempts when adding a new LocalUser/GroupIndex (#7091)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 19, 2024
1 parent 0532f66 commit 1267b3e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
4 changes: 4 additions & 0 deletions backend/canisters/group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Handle retry attempts when adding a new LocalGroupIndex ([#7091](https://github.com/open-chat-labs/open-chat/pull/7091))

## [[2.0.1519](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1519-group_index)] - 2024-12-19

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ async fn add_local_group_index_canister(args: Args) -> Response {
let wasm_version = result.canister_wasm.version;

if let Err(error) = set_controllers(args.canister_id, vec![result.this_canister_id]).await {
InternalError(format!("Failed to set controller: {error:?}"))
} else if let Err(error) = install_basic(args.canister_id, result.canister_wasm, result.init_args).await {
InternalError(format!("Failed to install canister: {error:?}"))
} else if let Err(error) = upgrade_group_wasm_in_local_group_index(
return InternalError(format!("Failed to set controller: {error:?}"));
}
if let Err(error) = install_basic(args.canister_id, result.canister_wasm, result.init_args).await {
if !error.1.contains("canister is not empty") {
return InternalError(format!("Failed to install canister: {error:?}"));
}
}
if let Err(error) = upgrade_group_wasm_in_local_group_index(
args.canister_id,
&result.group_canister_wasm,
result.group_canister_wasm_hash,
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Handle retry attempts when adding a new LocalUserIndex ([#7091](https://github.com/open-chat-labs/open-chat/pull/7091))

## [[2.0.1533](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1533-user_index)] - 2024-12-19

### Changed
Expand Down
16 changes: 16 additions & 0 deletions backend/canisters/user_index/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use crate::memory::get_upgrades_memory;
use crate::Data;
use canister_logger::LogEntry;
use canister_tracing_macros::trace;
use ic_cdk::api::management_canister::main::{CanisterSettings, LogVisibility, UpdateSettingsArgument};
use ic_cdk::post_upgrade;
use stable_memory::get_reader;
use std::time::Duration;
use tracing::info;
use user_index_canister::post_upgrade::Args;
use utils::cycles::init_cycles_dispenser_client;
Expand All @@ -26,4 +28,18 @@ fn post_upgrade(args: Args) {
init_state(env, data, args.wasm_version);

info!(version = %args.wasm_version, "Post-upgrade complete");

ic_cdk_timers::set_timer(Duration::ZERO, || ic_cdk::spawn(make_logs_public()));
}

async fn make_logs_public() {
ic_cdk::api::management_canister::main::update_settings(UpdateSettingsArgument {
canister_id: ic_cdk::id(),
settings: CanisterSettings {
log_visibility: Some(LogVisibility::Public),
..Default::default()
},
})
.await
.unwrap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ async fn add_local_user_index_canister(args: Args) -> Response {
let wasm_version = result.canister_wasm.version;

if let Err(error) = set_controllers(args.canister_id, vec![result.this_canister_id]).await {
InternalError(format!("Failed to set controller: {error:?}"))
} else if let Err(error) = install_basic(args.canister_id, result.canister_wasm, result.init_args).await {
InternalError(format!("Failed to install canister: {error:?}"))
} else if let Err(error) = upgrade_user_wasm_in_local_user_index(
return InternalError(format!("Failed to set controller: {error:?}"));
}
if let Err(error) = install_basic(args.canister_id, result.canister_wasm, result.init_args).await {
if !error.1.contains("canister is not empty") {
return InternalError(format!("Failed to install canister: {error:?}"));
}
}
if let Err(error) = upgrade_user_wasm_in_local_user_index(
args.canister_id,
&result.user_canister_wasm,
result.user_canister_wasm_hash,
Expand Down

0 comments on commit 1267b3e

Please sign in to comment.