refactor: create missing stacks
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 3m42s
Test / build (map[name:stable]) (push) Successful in 3m41s
Release Please / Release-plz (push) Failing after 1m0s

This commit is contained in:
Paul Campbell 2024-12-23 09:44:02 +00:00
parent b62060880b
commit 404782453a

View file

@ -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<Vec<Stack>> {
// 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<Self>;
@ -110,26 +141,14 @@ impl Actor for ImportStacksActor {
.filter(|s| this.selected_trello_stack_names.contains(s.name.as_ref()))
.collect::<Vec<_>>();
// 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());