Save local changes (GSC/Bing integrations) before merging PR #354
This commit is contained in:
@@ -56,6 +56,17 @@ async def check_and_execute_due_tasks(scheduler: 'TaskScheduler'):
|
||||
continue
|
||||
|
||||
try:
|
||||
# Check onboarding status first
|
||||
# Skip users who haven't completed onboarding to prevent premature agent initialization
|
||||
from services.onboarding.progress_service import OnboardingProgressService
|
||||
onboarding_service = OnboardingProgressService()
|
||||
status = onboarding_service.get_onboarding_status(user_id)
|
||||
|
||||
if not status.get("is_completed", False):
|
||||
# Skip logging for inactive users to reduce noise, unless debugging
|
||||
# logger.debug(f"[Scheduler Check] Skipping user {user_id} - Onboarding incomplete")
|
||||
continue
|
||||
|
||||
# Check active strategies for this user (for interval adjustment)
|
||||
try:
|
||||
from services.active_strategy_service import ActiveStrategyService
|
||||
|
||||
@@ -67,6 +67,27 @@ class SIFIndexingExecutor(TaskExecutor):
|
||||
# 2. Sync User Website Content (Deep Crawl / Snapshot)
|
||||
content_synced = await sif_service.sync_user_website_content(website_url)
|
||||
|
||||
# 3. Trigger Content Guardian Audit (Background Analysis)
|
||||
# This ensures the agent runs immediately after new data is indexed
|
||||
guardian_report = None
|
||||
if content_synced:
|
||||
try:
|
||||
from services.intelligence.agents.specialized_agents import ContentGuardianAgent
|
||||
# Re-use the intelligence service from sif_service
|
||||
guardian_agent = ContentGuardianAgent(
|
||||
intelligence_service=sif_service.intelligence_service,
|
||||
user_id=user_id,
|
||||
sif_service=sif_service
|
||||
)
|
||||
|
||||
logger.info("Triggering Content Guardian Site Audit...")
|
||||
guardian_report = await guardian_agent.perform_site_audit(website_url)
|
||||
|
||||
# Persist the audit report (optional, or rely on logs/alerts)
|
||||
# For now, we just include it in the task result
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to run Content Guardian audit: {e}")
|
||||
|
||||
# Determine overall success
|
||||
# We consider it a success if at least one operation worked, or if both were attempted without error
|
||||
# But ideally, content sync is the heavy lifter.
|
||||
@@ -91,6 +112,7 @@ class SIFIndexingExecutor(TaskExecutor):
|
||||
task_log.result_data = {
|
||||
"metadata_synced": metadata_synced,
|
||||
"content_synced": content_synced,
|
||||
"guardian_report": guardian_report,
|
||||
"website_url": website_url
|
||||
}
|
||||
task_log.execution_time_ms = int((time.time() - start_time) * 1000)
|
||||
|
||||
@@ -29,9 +29,10 @@ def load_due_sif_indexing_tasks(db: Session, user_id: str = None) -> List[SIFInd
|
||||
query = db.query(SIFIndexingTask).filter(
|
||||
or_(
|
||||
SIFIndexingTask.status == "pending",
|
||||
SIFIndexingTask.status == "active",
|
||||
SIFIndexingTask.status == "failed" # Retry failed tasks
|
||||
),
|
||||
SIFIndexingTask.next_run_at <= datetime.utcnow()
|
||||
SIFIndexingTask.next_execution <= datetime.utcnow()
|
||||
)
|
||||
|
||||
if user_id:
|
||||
|
||||
Reference in New Issue
Block a user