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,35 @@
|
||||
import time
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
from app.shared.config import get_settings
|
||||
from app.shared.database import get_db, init_schema
|
||||
from app.cron.daily_summary import generate_daily_summary
|
||||
from app.cron.cluster_unknowns import cluster_unknown_speakers
|
||||
from app.cron.purge_clips import purge_old_clips
|
||||
|
||||
|
||||
def run_nightly(settings, db):
|
||||
yesterday = (datetime.now(timezone.utc) - timedelta(days=1)).strftime("%Y-%m-%d")
|
||||
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
generate_daily_summary(yesterday, settings, db)
|
||||
cluster_unknown_speakers(settings, db)
|
||||
purge_old_clips(today, settings, db)
|
||||
|
||||
|
||||
def main():
|
||||
settings = get_settings()
|
||||
init_schema(settings)
|
||||
db = get_db(settings)
|
||||
|
||||
while True:
|
||||
now = datetime.now(timezone.utc)
|
||||
next_midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
if next_midnight <= now:
|
||||
next_midnight += timedelta(days=1)
|
||||
sleep_secs = (next_midnight - now).total_seconds()
|
||||
time.sleep(sleep_secs)
|
||||
run_nightly(settings, db)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user