feat(phase-30): add coverage snapshots, temporal comparison and auto re-testing (T-230 to T-232)
This commit is contained in:
@@ -18,6 +18,7 @@ from app.database import SessionLocal
|
||||
from app.services.mitre_sync_service import sync_mitre
|
||||
from app.services.intel_service import scan_intel
|
||||
from app.services.notification_service import cleanup_old_notifications
|
||||
from app.services.snapshot_service import create_snapshot, cleanup_old_snapshots
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -59,6 +60,26 @@ def _run_notification_cleanup() -> None:
|
||||
db.close()
|
||||
|
||||
|
||||
def _run_weekly_snapshot() -> None:
|
||||
"""Create a weekly coverage snapshot and clean up old ones."""
|
||||
logger.info("Scheduled weekly snapshot job starting...")
|
||||
db = SessionLocal()
|
||||
try:
|
||||
snapshot = create_snapshot(db, name="Auto-weekly")
|
||||
logger.info(
|
||||
"Weekly snapshot created — score %.1f, %d techniques",
|
||||
snapshot.organization_score,
|
||||
snapshot.total_techniques,
|
||||
)
|
||||
deleted = cleanup_old_snapshots(db, keep_last=52)
|
||||
if deleted:
|
||||
logger.info("Cleaned up %d old snapshots", deleted)
|
||||
except Exception:
|
||||
logger.exception("Weekly snapshot job failed")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def _run_intel_scan() -> None:
|
||||
"""Execute an intel scan inside its own DB session."""
|
||||
logger.info("Scheduled intel scan job starting...")
|
||||
@@ -111,5 +132,18 @@ def start_scheduler() -> None:
|
||||
name="Notification cleanup (daily)",
|
||||
replace_existing=True,
|
||||
)
|
||||
scheduler.add_job(
|
||||
_run_weekly_snapshot,
|
||||
trigger="cron",
|
||||
day_of_week="sun",
|
||||
hour=0,
|
||||
minute=0,
|
||||
id="weekly_snapshot",
|
||||
name="Weekly coverage snapshot (Sundays 00:00)",
|
||||
replace_existing=True,
|
||||
)
|
||||
scheduler.start()
|
||||
logger.info("Background scheduler started — mitre_sync (24h), intel_scan (7d), notification_cleanup (24h)")
|
||||
logger.info(
|
||||
"Background scheduler started — mitre_sync (24h), intel_scan (7d), "
|
||||
"notification_cleanup (24h), weekly_snapshot (Sundays 00:00)"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user