Pending transport failures remain inspectable before a service recovers.
(
root: &std::path::Path,
)
| 191 | |
| 192 | /// Pending transport failures remain inspectable before a service recovers. |
| 193 | pub fn pending( |
| 194 | root: &std::path::Path, |
| 195 | ) -> Result<Vec<(std::path::PathBuf, SessionLogEvent)>, String> { |
| 196 | let dir = root.join(".atomic/hook-log-pending"); |
| 197 | let entries = match std::fs::read_dir(dir) { |
| 198 | Ok(entries) => entries, |
| 199 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(Vec::new()), |
| 200 | Err(error) => return Err(error.to_string()), |
| 201 | }; |
| 202 | let mut events = Vec::new(); |
| 203 | for entry in entries { |
| 204 | let path = entry.map_err(|error| error.to_string())?.path(); |
| 205 | if path.extension().is_none_or(|extension| extension != "json") { |
| 206 | continue; |
| 207 | } |
| 208 | let bytes = match std::fs::read(&path) { |
| 209 | Ok(bytes) => bytes, |
| 210 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => continue, |
| 211 | Err(error) => return Err(error.to_string()), |
| 212 | }; |
| 213 | events.push(( |
| 214 | path, |
| 215 | serde_json::from_slice(&bytes).map_err(|error| error.to_string())?, |
| 216 | )); |
| 217 | } |
| 218 | Ok(events) |
| 219 | } |
| 220 | |
| 221 | /// Replay pending events idempotently while the service owns the database gate. |
| 222 | pub fn flush_pending( |