| 119 | /// Enqueue a rejected delta with full auth context. |
| 120 | #[allow(clippy::too_many_arguments)] |
| 121 | pub fn enqueue( |
| 122 | &mut self, |
| 123 | peer_id: u64, |
| 124 | user_id: u64, |
| 125 | tenant_id: u64, |
| 126 | delta: Vec<u8>, |
| 127 | constraint: &Constraint, |
| 128 | reason: String, |
| 129 | hint: CompensationHint, |
| 130 | ) -> Result<u64> { |
| 131 | if self.entries.len() >= self.capacity { |
| 132 | return Err(CrdtError::DlqFull { |
| 133 | capacity: self.capacity, |
| 134 | pending: self.entries.len(), |
| 135 | }); |
| 136 | } |
| 137 | |
| 138 | let id = self.next_id; |
| 139 | self.next_id += 1; |
| 140 | |
| 141 | let now = SystemTime::now() |
| 142 | .duration_since(UNIX_EPOCH) |
| 143 | .unwrap_or_default() |
| 144 | .as_millis() as u64; |
| 145 | |
| 146 | self.entries.push_back(DeadLetter { |
| 147 | id, |
| 148 | peer_id, |
| 149 | user_id, |
| 150 | tenant_id, |
| 151 | delta, |
| 152 | violated_constraint: constraint.name.clone(), |
| 153 | collection: constraint.collection.clone(), |
| 154 | reason, |
| 155 | hint, |
| 156 | rejected_at: now, |
| 157 | retry_count: 0, |
| 158 | }); |
| 159 | |
| 160 | Ok(id) |
| 161 | } |
| 162 | |
| 163 | /// Peek at the oldest dead letter without removing it. |
| 164 | pub fn peek(&self) -> Option<&DeadLetter> { |