asteroid_mq_model/
durable.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use typeshare::typeshare;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[typeshare]
7pub struct MessageDurableConfig {
8    // we should have a expire time
9    pub expire: DateTime<Utc>,
10    // once it reached the max_receiver, it will be removed
11    pub max_receiver: Option<u32>,
12}
13
14impl MessageDurableConfig {
15    pub fn new(expire: DateTime<Utc>) -> Self {
16        Self {
17            expire,
18            max_receiver: None,
19        }
20    }
21    pub fn new_pull(expire: DateTime<Utc>) -> Self {
22        Self {
23            expire,
24            max_receiver: Some(1),
25        }
26    }
27    pub fn with_max_receiver(mut self, max_receiver: u32) -> Self {
28        self.max_receiver = Some(max_receiver);
29        self
30    }
31    pub fn with_expire(mut self, expire: DateTime<Utc>) -> Self {
32        self.expire = expire;
33        self
34    }
35}