chore: add more tracing messages
Some checks failed
Test / build (map[name:stable]) (push) Successful in 6m42s
Test / build (map[name:nightly]) (push) Successful in 7m50s
Release Please / Release-plz (push) Failing after 48s

This commit is contained in:
Paul Campbell 2024-12-23 09:44:02 +00:00
parent d96dee302d
commit d65dbd18ee
8 changed files with 50 additions and 11 deletions

View file

@ -69,6 +69,7 @@ impl Actor for ImportAttachmentActor {
.with_context(|| f!("saving attachment {}", file_path.display()))?; // FIXME: (#6) handle error
let attachment_file = this.ctx.temp_fs.file(&attachment_path);
// - - - upload the attachment to nextcloud card
tracing::info!("Nextcloud: upload attachment");
let attachment = this
.ctx
.deck_client()
@ -103,6 +104,7 @@ impl Actor for ImportAttachmentActor {
dir.remove()
.with_context(|| f!("deleting temp dir {dir}"))?; // FIXME: (#6) handle error
tracing::info!("ImportAttachmentActor finished");
Ok(actor_ref.stop_gracefully().await?)
});
}

View file

@ -67,13 +67,17 @@ impl Actor for ImportCardActor {
let deck_client: DeckClient = this.ctx.deck_client();
p!(this.ctx.prt, "> Importing card: {}", this.trello_card.name);
tracing::info!(name = %this.trello_card.name, "importing card");
// - - create a nextcloud card
let title = NextcloudCardTitle::from(&this.trello_card.name);
let desc: Option<NextcloudCardDescription> = match this.trello_card.desc.len() {
0 => None,
_ => Some(NextcloudCardDescription::from(&this.trello_card.desc)),
};
let nextcloud_card = deck_client
tracing::info!("Nextcloud: Create card");
let nextcloud_card = this
.ctx
.deck_client()
.create_card(
this.nextcloud_board_id,
this.nextcloud_stack_id,
@ -86,6 +90,7 @@ impl Actor for ImportCardActor {
let mut limit = RateLimit::new("labels & attachments", 10, 10.0, this.ctx.now());
// - - for each label on the trello card
tracing::trace!(labels = ?this.trello_card.labels, "");
let mut labels = vec![];
std::mem::swap(&mut this.trello_card.labels, &mut labels);
for trello_label in labels.into_iter() {
@ -107,7 +112,10 @@ impl Actor for ImportCardActor {
}
ask!(this.rate_limit_actor, RequestToken)?;
let attachments = trello_client
tracing::info!("Trello: Fetch card for attachments");
let attachments = this
.ctx
.trello_client()
.card(&this.trello_card.id)
.await
.result?
@ -134,6 +142,7 @@ impl Actor for ImportCardActor {
}
if this.labels_children.is_empty() && this.attachments_children.is_empty() {
tracing::info!("ImportAttachmentActor finished");
Ok(actor_ref.stop_gracefully().await?)
} else {
Ok(())
@ -152,15 +161,18 @@ impl Actor for ImportCardActor {
match reason {
ActorStopReason::Normal => {}
_ => {
tracing::warn!(?reason, "card child died");
return Ok(Some(reason));
}
}
tracing::debug!(?this.labels_children, ?this.attachments_children, "card children");
if this.labels_children.is_empty() && this.attachments_children.is_empty() {
tracing::info!("ImportCardActor finished");
return Ok(Some(ActorStopReason::Normal));
}
tracing::info!("ImportCardActor not finished");
Ok(None)
});
}

View file

@ -48,7 +48,9 @@ impl Actor for ImportLabelActor {
trello_color: this.trello_label.color.clone()
}
)?; // FIXME: (#6) handle error
// - - - add the label to the nextcloud card
// - - - add the label to the nextcloud card
tracing::info!("Nextcloud: add label to card");
this.ctx
.deck_client()
.add_label_to_card(
@ -60,6 +62,7 @@ impl Actor for ImportLabelActor {
.await
.result?; // FIXME: (#6) handle error
tracing::info!("ImportLabelActor finished");
Ok(actor_ref.stop_gracefully().await?)
});
}

View file

@ -7,12 +7,13 @@ use kameo::{
message::{Context, Message},
Actor,
};
use tracing::instrument;
use crate::{
nextcloud::model::{
NextcloudBoardId, NextcloudLabelColour, NextcloudLabelId, NextcloudLabelTitle,
},
on_actor_start, p,
on_actor_start,
trello::model::label::{TrelloLabelColor, TrelloLabelName},
FullCtx,
};
@ -49,12 +50,14 @@ impl Actor for LabelsActor {
});
}
#[derive(Debug)]
pub(crate) struct LookupNextcloudLabelId {
pub(crate) trello_name: TrelloLabelName,
pub(crate) trello_color: TrelloLabelColor,
}
impl Message<LookupNextcloudLabelId> for LabelsActor {
type Reply = Result<NextcloudLabelId, kxio::Error>;
#[instrument(skip(self, _ctx))]
async fn handle(
&mut self,
msg: LookupNextcloudLabelId,
@ -64,29 +67,31 @@ impl Message<LookupNextcloudLabelId> for LabelsActor {
.lookup
.get(&NextcloudLabelTitle::new(msg.trello_name.as_ref()))
{
Some(nextcloud_label_id) => nextcloud_label_id,
Some(nextcloud_label_id) => {
tracing::info!(?nextcloud_label_id, "found");
nextcloud_label_id
}
None => {
p!(
self.ctx.prt,
">> Label not found in nextcloud board, creating"
);
let color_hex = get_color_hex(msg.trello_color.as_ref());
tracing::info!(color = ?msg.trello_color, ?color_hex, "Label not found in nextcloud board, creating");
let label = self
.ctx
.deck_client()
.create_label(
self.nextcloud_board_id,
&NextcloudLabelTitle::new(msg.trello_name.as_ref()),
&NextcloudLabelColour::new(get_color_hex(msg.trello_color.as_ref())),
&NextcloudLabelColour::new(color_hex),
)
.await
.result?;
tracing::info!(?label, "created");
self.lookup.insert(label.title.clone(), label.id);
self.lookup
.get(&NextcloudLabelTitle::new(msg.trello_name.as_ref()))
.expect("label was just inserted")
}
};
tracing::info!(?nextcloud_label_id, "responding");
Ok(*nextcloud_label_id)
}
}

View file

@ -104,6 +104,7 @@ impl Actor for ImportStackActor {
match reason {
ActorStopReason::Normal => {}
_ => {
tracing::warn!(?reason, "stack child died");
return Ok(Some(reason));
}
}

View file

@ -169,6 +169,7 @@ impl Actor for ImportStacksActor {
match reason {
ActorStopReason::Normal => {}
_ => {
tracing::warn!(?reason, "stacks child died");
return Ok(Some(reason));
}
}

View file

@ -17,6 +17,7 @@ impl Actor for Supervisor {
reason: ActorStopReason,
) -> Result<Option<ActorStopReason>, BoxError> {
// normally when ImportStacksActor stops it would not cause the supervisor to stop, but we want it to stop.
tracing::warn!(?reason, "supervisor child died");
Ok(Some(reason))
}
}

View file

@ -6,6 +6,7 @@ use kxio::{
};
use reqwest::multipart;
use serde_json::json;
use tracing::instrument;
use crate::nextcloud::model::NextcloudOrder;
use crate::{
@ -46,12 +47,14 @@ impl<'ctx> DeckClient<'ctx> {
)
}
#[instrument(skip_all)]
async fn request<T: for<'a> serde::Deserialize<'a>>(
&self,
url: impl Into<String>,
custom: fn(&Net, String) -> ReqBuilder,
) -> APIResult<T> {
let url = url.into();
tracing::trace!(?url);
APIResult::new(
with_exponential_backoff!(
&self.ctx,
@ -67,6 +70,7 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip_all)]
async fn request_with_body<T: for<'a> serde::Deserialize<'a>>(
&self,
url: impl Into<String>,
@ -91,20 +95,24 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip(self))]
pub(crate) async fn get_boards(&self) -> APIResult<Vec<Board>> {
self.request("boards", |net, url| net.get(url)).await
}
#[instrument(skip(self))]
pub(crate) async fn get_board(&self, board_id: NextcloudBoardId) -> APIResult<Board> {
self.request(f!("boards/{board_id}"), |net, url| net.get(url))
.await
}
#[instrument(skip(self))]
pub(crate) async fn get_stacks(&self, board_id: NextcloudBoardId) -> APIResult<Vec<Stack>> {
self.request(f!("boards/{board_id}/stacks"), |net, url| net.get(url))
.await
}
#[instrument(skip(self))]
pub(crate) async fn get_stack(
&self,
board_id: NextcloudBoardId,
@ -116,6 +124,7 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip(self))]
pub(crate) async fn create_stack(
&self,
board_id: NextcloudBoardId,
@ -134,6 +143,7 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip(self))]
pub(crate) async fn create_card(
&self,
board_id: NextcloudBoardId,
@ -157,6 +167,7 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip(self))]
pub(crate) async fn create_label(
&self,
board_id: NextcloudBoardId,
@ -175,6 +186,7 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip(self))]
pub(crate) async fn get_card(
&self,
board_id: NextcloudBoardId,
@ -188,6 +200,7 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip(self))]
pub(crate) async fn add_label_to_card(
&self,
board_id: NextcloudBoardId,
@ -206,6 +219,7 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
#[instrument(skip(self))]
pub(crate) async fn add_attachment_to_card(
&self,
board_id: NextcloudBoardId,