refactor: create missing stacks
This commit is contained in:
parent
b62060880b
commit
404782453a
1 changed files with 43 additions and 24 deletions
|
@ -8,15 +8,15 @@ use kameo::{
|
||||||
Actor,
|
Actor,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::import::rate_limit::RateLimitActor;
|
|
||||||
use crate::rate_limit::RateLimit;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
import::{labels::LabelsActor, stack::ImportStackActor},
|
import::{labels::LabelsActor, rate_limit::RateLimitActor, stack::ImportStackActor},
|
||||||
nextcloud::{
|
nextcloud::{
|
||||||
client::DeckClient,
|
client::DeckClient,
|
||||||
model::{NextcloudBoardId, Stack},
|
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},
|
trello::model::list::{TrelloList, TrelloListName},
|
||||||
FullCtx,
|
FullCtx,
|
||||||
};
|
};
|
||||||
|
@ -97,6 +97,37 @@ impl ImportStacksActor {
|
||||||
children: Default::default(),
|
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 {
|
impl Actor for ImportStacksActor {
|
||||||
type Mailbox = UnboundedMailbox<Self>;
|
type Mailbox = UnboundedMailbox<Self>;
|
||||||
|
@ -110,26 +141,14 @@ impl Actor for ImportStacksActor {
|
||||||
.filter(|s| this.selected_trello_stack_names.contains(s.name.as_ref()))
|
.filter(|s| this.selected_trello_stack_names.contains(s.name.as_ref()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
// get list of nextcloud stacks in the selected board
|
// get list of nextcloud stacks in the selected board
|
||||||
let nextcloud_stacks = this
|
let nextcloud_stacks = match this.stacks(&selected_trello_stacks).await {
|
||||||
.ctx
|
//
|
||||||
.deck_client()
|
Ok(o) => o,
|
||||||
.get_stacks(this.nextcloud_board_id)
|
Err(error) => {
|
||||||
.await
|
tracing::error!(?error, "failed to get stacks");
|
||||||
.result?;
|
return Ok(actor_ref.stop_gracefully().await?);
|
||||||
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 mut limit = RateLimit::new("stacks", 1, 0.1, this.ctx.now());
|
let mut limit = RateLimit::new("stacks", 1, 0.1, this.ctx.now());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue