Skip to content

Commit

Permalink
feat: reclaim cycles from available canisters as well (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-sawlani-yral authored Nov 21, 2024
1 parent eac8b32 commit 54067ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@

use ic_cdk_macros::update;

use crate::{guard::is_caller::is_caller_global_admin_or_controller, CANISTER_DATA};

#[update(guard = "is_caller_global_admin_or_controller")]
fn start_reclaiming_cycles_from_individual_canisters() -> Result<String, String>{
fn start_reclaiming_cycles_from_individual_canisters() -> Result<String, String> {
CANISTER_DATA.with_borrow(|canister_data| {
canister_data.all_subnet_orchestrator_canisters_list.iter().for_each(|subnet_orchestrator_id| {
ic_cdk::notify(*subnet_orchestrator_id, "reclaim_cycles_from_individual_canisters", ()).unwrap();
});
});
Ok("Success".into())
}
canister_data
.all_subnet_orchestrator_canisters_list
.iter()
.for_each(|subnet_orchestrator_id| {
ic_cdk::notify(
*subnet_orchestrator_id,
"reclaim_cycles_from_individual_canisters",
(),
)
.unwrap();
});
});
Ok("Success".into())
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use candid::Principal;
use ic_cdk::call;
use ic_cdk_macros::update;
use shared_utils::common::utils::{permissions::is_caller_controller, task::run_task_concurrently};
Expand All @@ -6,16 +7,24 @@ use crate::CANISTER_DATA;

#[update(guard = "is_caller_controller")]
fn reclaim_cycles_from_individual_canisters() {
ic_cdk::spawn(impl_reclaim_cycles_from_individual_canisters_and_send_to_plaform_orchestrator())
ic_cdk::spawn(impl_reclaim_cycles_from_individual_canisters_and_send_to_platform_orchestrator())
}

async fn impl_reclaim_cycles_from_individual_canisters_and_send_to_plaform_orchestrator() {
let canister_ids = CANISTER_DATA.with_borrow(|canister_data| {
canister_data.user_principal_id_to_canister_id_map.clone().into_values()
});
async fn impl_reclaim_cycles_from_individual_canisters_and_send_to_platform_orchestrator() {
let canister_ids: Vec<Principal> = CANISTER_DATA.with_borrow(|canister_data| {
let mut canister_ids: Vec<Principal> = canister_data
.user_principal_id_to_canister_id_map
.clone()
.into_values()
.collect();

canister_ids.extend(canister_data.available_canisters.iter());

let relcaim_cycles_from_canister_futures = canister_ids.map(|canister_id| {
call::<_ , ()>(canister_id, "return_cycles_to_user_index_canister", ())
canister_ids
});
run_task_concurrently(relcaim_cycles_from_canister_futures, 10, |_| {}, || false).await;

let reclaim_cycles_from_canister_futures = canister_ids
.into_iter()
.map(|canister_id| call::<_, ()>(canister_id, "return_cycles_to_user_index_canister", ()));
run_task_concurrently(reclaim_cycles_from_canister_futures, 10, |_| {}, || false).await;
}

0 comments on commit 54067ab

Please sign in to comment.