feat: add proactive cron tasks and systemd timers\n\n- 10 proactive tasks: ingest with self-healing & link suggestions, daily summary, health check, archive stale, tag normalizer, predictive links, auto assign review, import context buffer\n- systemd timers for scheduling (02:00/14:00 slots, 30min intervals, weekly)\n- all tasks tested and working\n\nRefs: #1
This commit is contained in:
56
cron_tasks/archive_stale.py
Normal file
56
cron_tasks/archive_stale.py
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Markiert Engramme mit access_count=0, die älter als 7 Tage sind, als 'archived'.
|
||||
Reduziert Graph-Clutter und verbessert Performance.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
import sys
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
BRAIN_DIR = Path("/root/.openclaw/workspace/second-brain")
|
||||
DB_PATH = BRAIN_DIR / "data" / "brain.sqlite"
|
||||
|
||||
def run():
|
||||
now = datetime.now(timezone.utc)
|
||||
cutoff = now - timedelta(days=7)
|
||||
|
||||
conn = sqlite3.connect(str(DB_PATH))
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
|
||||
# Engramme finden: access_count=0 UND created_at älter als 7 Tage
|
||||
c.execute("""
|
||||
SELECT id, metadata_json FROM engrams
|
||||
WHERE json_extract(metadata_json, '$.access_count') = 0
|
||||
AND created_at < ?
|
||||
""", (cutoff.isoformat(),))
|
||||
rows = c.fetchall()
|
||||
|
||||
archived = 0
|
||||
for r in rows:
|
||||
meta = json.loads(r["metadata_json"] or "{}")
|
||||
tags = meta.get("tags", [])
|
||||
if "archived" not in tags:
|
||||
tags.append("archived")
|
||||
meta["tags"] = tags
|
||||
c.execute("UPDATE engrams SET metadata_json = ?, modified_at = ? WHERE id = ?",
|
||||
(json.dumps(meta), now.isoformat(), r["id"]))
|
||||
archived += 1
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print(json.dumps({
|
||||
"success": True,
|
||||
"time": now.isoformat(),
|
||||
"archived_count": archived,
|
||||
"cutoff_date": cutoff.isoformat(),
|
||||
}, indent=2, ensure_ascii=False))
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
Reference in New Issue
Block a user