feat: processed-event ledger, idempotent dispatch
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
mod enrichment_staleness;
|
||||
mod import_cleanup;
|
||||
mod movie_dedup;
|
||||
mod processed_events_cleanup;
|
||||
mod refresh_session_cleanup;
|
||||
mod watch_event_cleanup;
|
||||
mod wrapup;
|
||||
@@ -8,6 +9,7 @@ mod wrapup;
|
||||
pub use enrichment_staleness::EnrichmentStalenessJob;
|
||||
pub use import_cleanup::ImportSessionCleanupJob;
|
||||
pub use movie_dedup::MovieDeduplicationJob;
|
||||
pub use processed_events_cleanup::{PROCESSED_EVENTS_RETENTION_DAYS, ProcessedEventsCleanupJob};
|
||||
pub use refresh_session_cleanup::RefreshSessionCleanupJob;
|
||||
pub use watch_event_cleanup::WatchEventCleanupJob;
|
||||
pub use wrapup::{WrapUpAutoGenerateJob, WrapUpCleanupJob};
|
||||
|
||||
39
crates/application/src/jobs/processed_events_cleanup.rs
Normal file
39
crates/application/src/jobs/processed_events_cleanup.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use domain::{
|
||||
errors::DomainError,
|
||||
ports::{PeriodicJob, ProcessedEventLedger},
|
||||
};
|
||||
|
||||
/// Ledger rows older than this can no longer matter: the queue gives up on an
|
||||
/// event long before, so it cannot be redelivered.
|
||||
pub const PROCESSED_EVENTS_RETENTION_DAYS: i64 = 30;
|
||||
|
||||
pub struct ProcessedEventsCleanupJob {
|
||||
ledger: Arc<dyn ProcessedEventLedger>,
|
||||
}
|
||||
|
||||
impl ProcessedEventsCleanupJob {
|
||||
pub fn new(ledger: Arc<dyn ProcessedEventLedger>) -> Self {
|
||||
Self { ledger }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl PeriodicJob for ProcessedEventsCleanupJob {
|
||||
fn interval(&self) -> Duration {
|
||||
Duration::from_secs(24 * 3600)
|
||||
}
|
||||
|
||||
async fn run(&self) -> Result<(), DomainError> {
|
||||
let cutoff = chrono::Utc::now().naive_utc()
|
||||
- chrono::Duration::days(PROCESSED_EVENTS_RETENTION_DAYS);
|
||||
let n = self.ledger.delete_older_than(cutoff).await?;
|
||||
if n > 0 {
|
||||
tracing::info!("processed events cleanup: removed {n} ledger rows");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user