31 lines
882 B
Python
31 lines
882 B
Python
#!/usr/bin/env python3
|
|
"""Bereinigt abgelaufene temporaere Memory-Items. Laeuft als Cronjob."""
|
|
|
|
import sys
|
|
import os
|
|
import time
|
|
import logging
|
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
|
|
logging.basicConfig(format="%(asctime)s [memory-cleanup] %(message)s", level=logging.INFO)
|
|
log = logging.getLogger("memory-cleanup")
|
|
|
|
import memory_client
|
|
|
|
|
|
def cleanup():
|
|
items = memory_client.get_active_memory()
|
|
now_ts = int(time.time())
|
|
archived = 0
|
|
for item in items:
|
|
exp = item.get("expires_at")
|
|
if exp and exp < now_ts:
|
|
memory_client._patch(f"/memory/{item['id']}", {"status": "archived"})
|
|
log.info("Archiviert: [%s] %s (abgelaufen)", item["id"], item["content"][:60])
|
|
archived += 1
|
|
log.info("Cleanup fertig: %d archiviert, %d aktiv", archived, len(items) - archived)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
cleanup()
|