From d65dbd18ee6ba20e08f5c69056e52f553e896d22 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 23 Dec 2024 09:44:02 +0000 Subject: [PATCH] chore: add more tracing messages --- src/import/attachment.rs | 2 ++ src/import/card.rs | 16 ++++++++++++++-- src/import/label.rs | 5 ++++- src/import/labels.rs | 21 +++++++++++++-------- src/import/stack.rs | 1 + src/import/stacks.rs | 1 + src/import/supervisor.rs | 1 + src/nextcloud/client.rs | 14 ++++++++++++++ 8 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/import/attachment.rs b/src/import/attachment.rs index 5515c36..0db7f84 100644 --- a/src/import/attachment.rs +++ b/src/import/attachment.rs @@ -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?) }); } diff --git a/src/import/card.rs b/src/import/card.rs index 32a4203..08e956c 100644 --- a/src/import/card.rs +++ b/src/import/card.rs @@ -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 = 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) }); } diff --git a/src/import/label.rs b/src/import/label.rs index d4d4877..dc51b3d 100644 --- a/src/import/label.rs +++ b/src/import/label.rs @@ -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?) }); } diff --git a/src/import/labels.rs b/src/import/labels.rs index df8c52e..5bbad49 100644 --- a/src/import/labels.rs +++ b/src/import/labels.rs @@ -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 for LabelsActor { type Reply = Result; + #[instrument(skip(self, _ctx))] async fn handle( &mut self, msg: LookupNextcloudLabelId, @@ -64,29 +67,31 @@ impl Message 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) } } diff --git a/src/import/stack.rs b/src/import/stack.rs index f565036..48ebf48 100644 --- a/src/import/stack.rs +++ b/src/import/stack.rs @@ -104,6 +104,7 @@ impl Actor for ImportStackActor { match reason { ActorStopReason::Normal => {} _ => { + tracing::warn!(?reason, "stack child died"); return Ok(Some(reason)); } } diff --git a/src/import/stacks.rs b/src/import/stacks.rs index 8a19847..ca75a84 100644 --- a/src/import/stacks.rs +++ b/src/import/stacks.rs @@ -169,6 +169,7 @@ impl Actor for ImportStacksActor { match reason { ActorStopReason::Normal => {} _ => { + tracing::warn!(?reason, "stacks child died"); return Ok(Some(reason)); } } diff --git a/src/import/supervisor.rs b/src/import/supervisor.rs index 72fb81e..3ae6ac1 100644 --- a/src/import/supervisor.rs +++ b/src/import/supervisor.rs @@ -17,6 +17,7 @@ impl Actor for Supervisor { reason: ActorStopReason, ) -> Result, 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)) } } diff --git a/src/nextcloud/client.rs b/src/nextcloud/client.rs index d472e5b..eca89a9 100644 --- a/src/nextcloud/client.rs +++ b/src/nextcloud/client.rs @@ -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 serde::Deserialize<'a>>( &self, url: impl Into, custom: fn(&Net, String) -> ReqBuilder, ) -> APIResult { 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 serde::Deserialize<'a>>( &self, url: impl Into, @@ -91,20 +95,24 @@ impl<'ctx> DeckClient<'ctx> { .await } + #[instrument(skip(self))] pub(crate) async fn get_boards(&self) -> APIResult> { self.request("boards", |net, url| net.get(url)).await } + #[instrument(skip(self))] pub(crate) async fn get_board(&self, board_id: NextcloudBoardId) -> APIResult { 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> { 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,