use iggy_common::{Identifier, IggyError, IggyMessage, Partitioning};
use std::fmt::Debug;
use std::pin::Pin;
use std::sync::Arc;
use tracing::error;
#[derive(Debug)]
pub struct ErrorCtx {
pub cause: Box<IggyError>,
pub stream: Arc<Identifier>,
pub stream_name: String,
pub topic: Arc<Identifier>,
pub topic_name: String,
pub partitioning: Option<Arc<Partitioning>>,
pub messages: Arc<Vec<IggyMessage>>,
}
pub trait ErrorCallback: Send + Sync + Debug + 'static {
fn call(&self, ctx: ErrorCtx) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>;
}
#[derive(Debug, Default)]
pub struct LogErrorCallback;
impl ErrorCallback for LogErrorCallback {
fn call(&self, ctx: ErrorCtx) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>> {
Box::pin(async move {
let partitioning = ctx
.partitioning
.as_ref()
.map(|p| format!("{p:?}"))
.unwrap_or_else(|| "None".to_string());
error!(
cause = %ctx.cause,
stream = %ctx.stream,
stream_name = ctx.stream_name,
topic = %ctx.topic,
topic_name = ctx.topic_name,
partitioning = %partitioning,
num_messages = ctx.messages.len(),
"Failed to send messages in background task",
);
})
}
}