feat: extract handler

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-08-14 14:47:19 +02:00
parent 101a266ea2
commit b6afcc700c
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 39 additions and 43 deletions

View File

@ -1,45 +1,3 @@
pub mod consumers;
pub mod handler;
pub mod staging;
pub mod handler {
use std::sync::Arc;
use super::{
consumers::{Consumer, PartitionKey, Topic, TopicOffset},
staging::Staging,
};
#[derive(Clone)]
pub struct Handler {
staging: Arc<Staging>,
}
impl Handler {
pub fn new(staging: Staging) -> Self {
Self {
staging: Arc::new(staging),
}
}
pub fn handle_offset(
&self,
topic: &Topic,
partition_key: &Option<PartitionKey>,
consumer: &Consumer,
offset: TopicOffset,
) -> anyhow::Result<()> {
let events = self.staging.get_topic_offset(
topic,
partition_key.clone(),
consumer.offset,
offset,
)?;
// TODO: handle events
for event in events {
tracing::trace!("handling event: {:?}", event);
}
Ok(())
}
}
}

View File

@ -0,0 +1,38 @@
use std::sync::Arc;
use super::{
consumers::{Consumer, PartitionKey, Topic, TopicOffset},
staging::Staging,
};
#[derive(Clone)]
pub struct Handler {
staging: Arc<Staging>,
}
impl Handler {
pub fn new(staging: Staging) -> Self {
Self {
staging: Arc::new(staging),
}
}
pub fn handle_offset(
&self,
topic: &Topic,
partition_key: &Option<PartitionKey>,
consumer: &Consumer,
offset: TopicOffset,
) -> anyhow::Result<()> {
let events =
self.staging
.get_topic_offset(topic, partition_key.clone(), consumer.offset, offset)?;
// TODO: handle events
for event in events {
tracing::trace!("handling event: {:?}", event);
}
Ok(())
}
}