feat(phase-31): add campaign scheduling and recurring automation (T-233 to T-234)
This commit is contained in:
@@ -19,6 +19,7 @@ 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
|
||||
from app.services.campaign_scheduler_service import check_and_run_recurring_campaigns
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -80,6 +81,19 @@ def _run_weekly_snapshot() -> None:
|
||||
db.close()
|
||||
|
||||
|
||||
def _run_recurring_campaigns() -> None:
|
||||
"""Check and run any due recurring campaigns."""
|
||||
logger.info("Scheduled recurring campaigns check starting...")
|
||||
db = SessionLocal()
|
||||
try:
|
||||
spawned = check_and_run_recurring_campaigns(db)
|
||||
logger.info("Recurring campaigns check finished — spawned %d campaigns", spawned)
|
||||
except Exception:
|
||||
logger.exception("Recurring campaigns check 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...")
|
||||
@@ -142,8 +156,17 @@ def start_scheduler() -> None:
|
||||
name="Weekly coverage snapshot (Sundays 00:00)",
|
||||
replace_existing=True,
|
||||
)
|
||||
scheduler.add_job(
|
||||
_run_recurring_campaigns,
|
||||
trigger="interval",
|
||||
hours=24,
|
||||
id="recurring_campaigns",
|
||||
name="Recurring campaigns check (daily)",
|
||||
replace_existing=True,
|
||||
)
|
||||
scheduler.start()
|
||||
logger.info(
|
||||
"Background scheduler started — mitre_sync (24h), intel_scan (7d), "
|
||||
"notification_cleanup (24h), weekly_snapshot (Sundays 00:00)"
|
||||
"notification_cleanup (24h), weekly_snapshot (Sundays 00:00), "
|
||||
"recurring_campaigns (daily)"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user