Skip to content

Commit

Permalink
Use tracing crate to log outcome of each call to push_events
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Feb 8, 2024
1 parent 42133a4 commit af5a97f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde = "1.0.196"
serde_bytes = "0.11.14"
tokio = "1.36.0"
tokio-util = "0.7.10"
tracing = "0.1.40"

[patch.crates-io]
pocket-ic = { git = "https://github.com/dfinity/ic", rev = "044cfd5147fc97d7e5a214966941b6580c325d72" }
1 change: 1 addition & 0 deletions client/cdk_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ ic-cdk-timers.workspace = true
ic_principal.workspace = true
rand.workspace = true
serde.workspace = true
tracing.workspace = true
10 changes: 7 additions & 3 deletions client/cdk_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::time::Duration;
use tracing::error;

pub struct CdkRuntime {
rng: StdRng,
Expand Down Expand Up @@ -50,11 +51,14 @@ async fn flush_async<F: FnOnce()>(
events: Vec<IdempotentEvent>,
trigger_retry: F,
) {
if ic_cdk::call::<_, ()>(canister_id, "push_events", (PushEventsArgs { events },))
.await
.is_err()
let events_len = events.len();
if let Err(error) =
ic_cdk::call::<_, ()>(canister_id, "push_events", (PushEventsArgs { events },)).await
{
trigger_retry();
error!(?error, %canister_id, events = events_len, "Failed to call 'push_events'");
} else {
error!(%canister_id, events = events_len, "Successfully pushed events");
}
}

Expand Down
4 changes: 3 additions & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use std::time::Duration;
const DEFAULT_FLUSH_DELAY: Duration = Duration::from_secs(300);
const DEFAULT_MAX_BATCH_SIZE: u32 = 1000;

pub struct Client<R> {
pub struct EventSinkClient<R> {
inner: Arc<Mutex<ClientInner<R>>>,
}

type Client<R> = EventSinkClient<R>;

#[derive(Serialize, Deserialize)]
struct ClientInner<R> {
event_sink_canister_id: Principal,
Expand Down

0 comments on commit af5a97f

Please sign in to comment.