[30388f42] Infrastructure Hardening & Final Touches: Stabilized Lead Engine (Nginx routing, manager.py, Dockerfile fixes), restored known-good Nginx configs, and ensured all recent fixes are committed. System is ready for migration.

- Fixed Nginx proxy for /feedback/ and /lead/ routes.
- Restored manager.py to use persistent SQLite DB and corrected test lead triggers.
- Refined Dockerfile for lead-engine to ensure clean dependency installs.
- Applied latest API configs (.env) to lead-engine and duckdns services.
- Updated documentation (GEMINI.md, readme.md, RELOCATION.md, lead-engine/README.md) to reflect final state and lessons learned.
- Committed all pending changes to main branch.
This commit is contained in:
2026-03-07 20:01:48 +00:00
parent 592d04a32a
commit 57081bf102
10 changed files with 335 additions and 683 deletions

View File

@@ -4,28 +4,37 @@ import logging
import os
import sys
# Path setup to import local modules
sys.path.append(os.path.dirname(__file__))
from db import get_leads
from enrich import refresh_ce_data
# Import our new Trading Twins Orchestrator
try:
from trading_twins.orchestrator import TradingTwinsOrchestrator
except ImportError:
# Fallback for dev environment or missing dependencies
TradingTwinsOrchestrator = None
import time
import json
import logging
import os
import sys
import threading
import uvicorn
# Setup logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger("lead-monitor")
# Ensure the lead-engine root is in path for imports
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
if BASE_DIR not in sys.path:
sys.path.append(BASE_DIR)
from db import get_leads
from enrich import refresh_ce_data
# Import the core logic from manager
try:
from trading_twins.manager import process_lead as start_trading_twins_workflow
logger.info("✅ Trading Twins modules imported successfully.")
except ImportError as e:
logger.error(f"❌ Failed to import trading_twins: {e}")
start_trading_twins_workflow = None
def run_monitor():
logger.info("Starting Lead Monitor (Polling CE for updates)...")
# Initialize Orchestrator once
orchestrator = TradingTwinsOrchestrator() if TradingTwinsOrchestrator else None
while True:
try:
leads = get_leads()
@@ -56,22 +65,26 @@ def run_monitor():
logger.info(f" [SUCCESS] Analysis finished for {lead['company_name']}: {new_vertical}")
# Trigger Trading Twins Process
if orchestrator:
logger.info(f" [ACTION] Triggering Trading Twins Orchestrator for {lead['company_name']}...")
if start_trading_twins_workflow:
logger.info(f" [ACTION] Triggering Trading Twins Process for {lead['company_name']}...")
try:
# Extract contact details safely
# Extract details for the manager.process_lead function
email = lead.get('email')
name = lead.get('contact_name', 'Interessent')
company = lead.get('company_name', 'Ihre Firma')
opener = new_data.get('ai_opener') or "Vielen Dank für Ihre Anfrage."
request_id = f"lead_{lead['id']}_{int(time.time())}"
if email:
orchestrator.process_lead(email, name, company)
# Calling the function from manager.py
# Signature: process_lead(request_id, company, opener, receiver)
start_trading_twins_workflow(request_id, company, opener, email)
else:
logger.warning(f" [SKIP] No email address found for lead {lead['id']}")
except Exception as e:
logger.error(f" [ERROR] Failed to trigger orchestrator: {e}")
logger.error(f" [ERROR] Failed to start workflow: {e}")
else:
logger.warning(" [SKIP] Orchestrator not available (Import Error)")
logger.warning(" [SKIP] Workflow Logic not available (Import Error)")
except Exception as e:
logger.error(f"Monitor error: {e}")