feat(signature): Signaturen beim Report-Upload behalten + Cron-Cleanup nach Frist
Bisher loeschte die Report-Pipeline die Unterschriften nach erfolgreichem DOCUframe-Upload. Wir brauchen die Signatur-Dateien aber weiterhin, daher: - ProcessDeliveryReportUseCase: Signatur-Loeschung (delete_for_delivery) aus dem Cleanup entfernt + SignatureStorage-Dependency raus (Report-PDF/Bild-Notiz- Cleanup bleibt). - SignatureStorage: neue Methode delete_older_than(max_age) -> Anzahl; lokaler Adapter loescht PNGs aelter als die Frist (per mtime). - Config [signature]: retention_days (Default 90, 0 = aus) + cleanup_cron (Default taeglich 04:00). - main.rs: Signatur-Cleanup-Scheduler (gated retention_days > 0). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
//! Pfad — so bleibt ein Umzug des Verzeichnisses unkompliziert.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use uuid::Uuid;
|
||||
@ -96,4 +97,48 @@ impl SignatureStorage for LocalSignatureStorage {
|
||||
ApplicationError::Repository(format!("signatur löschen fehlgeschlagen: {e}"))
|
||||
})
|
||||
}
|
||||
|
||||
async fn delete_older_than(&self, max_age: Duration) -> Result<u64, ApplicationError> {
|
||||
let base = self.base_dir.clone();
|
||||
tokio::task::spawn_blocking(move || -> std::io::Result<u64> {
|
||||
let now = SystemTime::now();
|
||||
let entries = match std::fs::read_dir(&base) {
|
||||
Ok(e) => e,
|
||||
// Verzeichnis (noch) nicht vorhanden → nichts zu löschen.
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(0),
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
let mut deleted = 0u64;
|
||||
for entry in entries {
|
||||
let entry = entry?;
|
||||
let meta = match entry.metadata() {
|
||||
Ok(m) => m,
|
||||
Err(_) => continue,
|
||||
};
|
||||
if !meta.is_file() {
|
||||
continue;
|
||||
}
|
||||
// Alter über die letzte Änderung (mtime) bestimmen. Lässt sich
|
||||
// die mtime nicht lesen, Datei vorsichtshalber NICHT löschen.
|
||||
let modified = match meta.modified() {
|
||||
Ok(t) => t,
|
||||
Err(_) => continue,
|
||||
};
|
||||
let age = now.duration_since(modified).unwrap_or(Duration::ZERO);
|
||||
if age > max_age {
|
||||
match std::fs::remove_file(entry.path()) {
|
||||
Ok(()) => deleted += 1,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(deleted)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| ApplicationError::Repository(format!("join error: {e}")))?
|
||||
.map_err(|e| {
|
||||
ApplicationError::Repository(format!("signatur-cleanup fehlgeschlagen: {e}"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user