diff --git a/src/import/stacks.rs b/src/import/stacks.rs index ca75a84..3dfbd5f 100644 --- a/src/import/stacks.rs +++ b/src/import/stacks.rs @@ -8,15 +8,15 @@ use kameo::{ Actor, }; -use crate::import::rate_limit::RateLimitActor; -use crate::rate_limit::RateLimit; use crate::{ - import::{labels::LabelsActor, stack::ImportStackActor}, + import::{labels::LabelsActor, rate_limit::RateLimitActor, stack::ImportStackActor}, nextcloud::{ client::DeckClient, model::{NextcloudBoardId, Stack}, }, - on_actor_link_died, on_actor_start, p, spawn_in_thread, + on_actor_link_died, on_actor_start, p, + rate_limit::RateLimit, + spawn_in_thread, trello::model::list::{TrelloList, TrelloListName}, FullCtx, }; @@ -97,6 +97,37 @@ impl ImportStacksActor { children: Default::default(), } } + + async fn stacks( + &self, + selected_trello_stacks: &[TrelloList], + ) -> color_eyre::Result> { + // get list of nextcloud stacks in the selected board + let nextcloud_stacks = self + .ctx + .deck_client() + .get_stacks(self.nextcloud_board_id) + .await + .result?; + tracing::info!("creating missing stacks"); + create_any_missing_stacks( + &self.ctx, + selected_trello_stacks, + self.nextcloud_board_id, + nextcloud_stacks, + ) + .await?; + tracing::info!("created missing stacks"); + // - get the list of nextcloud stacks again (with new stack ids) + let nextcloud_stacks = self + .ctx + .deck_client() + .get_stacks(self.nextcloud_board_id) + .await + .result?; + + Ok(nextcloud_stacks) + } } impl Actor for ImportStacksActor { type Mailbox = UnboundedMailbox; @@ -110,26 +141,14 @@ impl Actor for ImportStacksActor { .filter(|s| this.selected_trello_stack_names.contains(s.name.as_ref())) .collect::>(); // get list of nextcloud stacks in the selected board - let nextcloud_stacks = this - .ctx - .deck_client() - .get_stacks(this.nextcloud_board_id) - .await - .result?; - create_any_missing_stacks( - &this.ctx, - &selected_trello_stacks, - this.nextcloud_board_id, - nextcloud_stacks, - ) - .await?; - // - get the list of nextcloud stacks again (with new stack ids) - let nextcloud_stacks = this - .ctx - .deck_client() - .get_stacks(this.nextcloud_board_id) - .await - .result?; + let nextcloud_stacks = match this.stacks(&selected_trello_stacks).await { + // + Ok(o) => o, + Err(error) => { + tracing::error!(?error, "failed to get stacks"); + return Ok(actor_ref.stop_gracefully().await?); + } + }; let mut limit = RateLimit::new("stacks", 1, 0.1, this.ctx.now());