feat: cron jobs — daily summary, speaker clustering, clip purge
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import sqlite3
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from app.shared.config import Settings
|
||||
|
||||
|
||||
def purge_old_clips(today: str, settings: Settings, db: sqlite3.Connection) -> None:
|
||||
cutoff = datetime.strptime(today, "%Y-%m-%d") - timedelta(days=settings.clip_retention_days)
|
||||
clips_root = Path(settings.clips_dir)
|
||||
if not clips_root.exists():
|
||||
return
|
||||
for date_dir in clips_root.iterdir():
|
||||
if not date_dir.is_dir():
|
||||
continue
|
||||
try:
|
||||
dir_date = datetime.strptime(date_dir.name, "%Y-%m-%d")
|
||||
except ValueError:
|
||||
continue
|
||||
if dir_date < cutoff:
|
||||
for wav in date_dir.glob("*.wav"):
|
||||
wav.unlink()
|
||||
try:
|
||||
date_dir.rmdir()
|
||||
except OSError:
|
||||
pass
|
||||
cutoff_str = cutoff.strftime("%Y-%m-%d")
|
||||
db.execute(
|
||||
"UPDATE utterances SET audio_clip_path=NULL WHERE date(start_time) < ?",
|
||||
(cutoff_str,),
|
||||
)
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user