use crate::common::model::{
Request, Response,
message::{TaskErrorEvent, TaskEvent, TaskParserEvent},
};
use crate::errors::Result;
use crate::utils::logger::LogModel;
use async_trait::async_trait;
use std::sync::Arc;
pub trait Identifiable {
fn get_id(&self) -> String;
fn partition_key(&self) -> String {
self.get_id()
}
}
impl Identifiable for LogModel {
fn get_id(&self) -> String {
self.request_id
.map(|id| id.to_string())
.unwrap_or_else(|| self.task_id.clone())
}
}
impl Identifiable for Request {
fn get_id(&self) -> String {
self.id.to_string()
}
}
impl Identifiable for Response {
fn get_id(&self) -> String {
self.id.to_string()
}
}
impl Identifiable for TaskParserEvent {
fn get_id(&self) -> String {
self.id.to_string()
}
}
impl Identifiable for TaskErrorEvent {
fn get_id(&self) -> String {
self.id.to_string()
}
}
impl Identifiable for TaskEvent {
fn get_id(&self) -> String {
self.run_id.to_string()
}
fn partition_key(&self) -> String {
self.account.clone()
}
}
#[async_trait]
pub trait Compensator: Send + Sync {
async fn add_task(&self, topic: &str, id: &str, payload: Arc<Vec<u8>>) -> Result<()>;
async fn remove_task(&self, topic: &str, id: &str) -> Result<()>;
}