feat: processed-event ledger, idempotent dispatch

This commit is contained in:
2026-10-26 00:17:28 +01:00
parent fa8e94817a
commit 5681d0c034
29 changed files with 610 additions and 24 deletions

View File

@@ -0,0 +1,35 @@
use application::jobs::{PROCESSED_EVENTS_RETENTION_DAYS, ProcessedEventsCleanupJob};
use domain::{events::EventId, ports::PeriodicJob, testing::InMemoryStore};
#[tokio::test]
async fn removes_only_rows_older_than_the_retention_window() {
let store = InMemoryStore::new();
let now = chrono::Utc::now().naive_utc();
let stale = EventId::new();
let fresh = EventId::new();
store.seed_processed_event(
&stale,
"h",
now - chrono::Duration::days(PROCESSED_EVENTS_RETENTION_DAYS + 1),
);
store.seed_processed_event(
&fresh,
"h",
now - chrono::Duration::days(PROCESSED_EVENTS_RETENTION_DAYS - 1),
);
ProcessedEventsCleanupJob::new(store.clone())
.run()
.await
.unwrap();
use domain::ports::ProcessedEventLedger;
assert!(!store.has_processed(&stale, "h").await.unwrap());
assert!(store.has_processed(&fresh, "h").await.unwrap());
}
#[test]
fn runs_daily() {
let job = ProcessedEventsCleanupJob::new(InMemoryStore::new());
assert_eq!(job.interval(), std::time::Duration::from_secs(86_400));
}