Update app/routes/pipeline.py
Browse files- app/routes/pipeline.py +15 -2
app/routes/pipeline.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
# app/routes/pipeline.py
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from fastapi import APIRouter, Depends, Query
|
| 4 |
from datetime import datetime
|
| 5 |
from agent_manager import AgentManager
|
|
@@ -12,6 +14,8 @@ router = APIRouter(
|
|
| 12 |
dependencies=[Depends(require_api_key)]
|
| 13 |
)
|
| 14 |
|
|
|
|
|
|
|
| 15 |
@router.on_event("startup")
|
| 16 |
def startup_db():
|
| 17 |
init_db()
|
|
@@ -23,12 +27,21 @@ def run_pipeline(
|
|
| 23 |
):
|
| 24 |
manager = AgentManager(niche, business_type)
|
| 25 |
summary = manager.run_all()
|
|
|
|
| 26 |
for agent_name, result in summary.items():
|
| 27 |
log_action(agent_name, "pipeline_run", result)
|
| 28 |
-
|
| 29 |
-
"status": "pipeline_executed",
|
| 30 |
"niche": niche,
|
| 31 |
"business_type": business_type,
|
| 32 |
"results": summary,
|
| 33 |
"timestamp": datetime.utcnow().isoformat()
|
| 34 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# app/routes/pipeline.py
|
| 2 |
|
| 3 |
+
import os
|
| 4 |
+
import requests
|
| 5 |
from fastapi import APIRouter, Depends, Query
|
| 6 |
from datetime import datetime
|
| 7 |
from agent_manager import AgentManager
|
|
|
|
| 14 |
dependencies=[Depends(require_api_key)]
|
| 15 |
)
|
| 16 |
|
| 17 |
+
WEBHOOK_URL = os.getenv("ZAPIER_WEBHOOK") # Set this in HF Secrets
|
| 18 |
+
|
| 19 |
@router.on_event("startup")
|
| 20 |
def startup_db():
|
| 21 |
init_db()
|
|
|
|
| 27 |
):
|
| 28 |
manager = AgentManager(niche, business_type)
|
| 29 |
summary = manager.run_all()
|
| 30 |
+
# Log each step
|
| 31 |
for agent_name, result in summary.items():
|
| 32 |
log_action(agent_name, "pipeline_run", result)
|
| 33 |
+
payload = {
|
|
|
|
| 34 |
"niche": niche,
|
| 35 |
"business_type": business_type,
|
| 36 |
"results": summary,
|
| 37 |
"timestamp": datetime.utcnow().isoformat()
|
| 38 |
}
|
| 39 |
+
# Fire the Zapier webhook (non‑blocking)
|
| 40 |
+
try:
|
| 41 |
+
requests.post(WEBHOOK_URL, json=payload, timeout=2)
|
| 42 |
+
except Exception:
|
| 43 |
+
pass
|
| 44 |
+
return {
|
| 45 |
+
"status": "pipeline_executed",
|
| 46 |
+
**payload
|
| 47 |
+
}
|