feat: init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TransportEnvelope<T> {
|
||||
#[serde(default = "Uuid::now_v7")]
|
||||
pub message_id: Uuid,
|
||||
pub request_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub payload: T,
|
||||
#[serde(default = "default_timestamp")]
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
#[serde(default)]
|
||||
pub attempt: u8,
|
||||
}
|
||||
|
||||
fn default_timestamp() -> chrono::DateTime<chrono::Utc> {
|
||||
chrono::Utc::now()
|
||||
}
|
||||
|
||||
impl<T> TransportEnvelope<T> {
|
||||
pub fn new(request_id: Uuid, user_id: Uuid, payload: T) -> Self {
|
||||
Self {
|
||||
message_id: Uuid::now_v7(),
|
||||
request_id,
|
||||
user_id,
|
||||
payload,
|
||||
created_at: chrono::Utc::now(),
|
||||
attempt: 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn retry(self) -> Self {
|
||||
Self {
|
||||
attempt: self.attempt + 1,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user