Fix Run Now: mount agents in container, install deps, fix datetime bug
This commit is contained in:
@@ -2,7 +2,7 @@ FROM python:3.12-slim
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN pip install --no-cache-dir fastapi uvicorn sqlalchemy
|
RUN pip install --no-cache-dir fastapi uvicorn sqlalchemy caldav icalendar recurring-ical-events requests
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
|||||||
+18
-13
@@ -461,24 +461,28 @@ def trigger_instance(instance_id: int, user: dict = Depends(require_auth), db: S
|
|||||||
catalog_id = inst.catalog_id
|
catalog_id = inst.catalog_id
|
||||||
u = db.query(User).filter(User.id == user["user_id"]).first()
|
u = db.query(User).filter(User.id == user["user_id"]).first()
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
agent_dir = "/app/agents"
|
||||||
|
env = {**dict(os.environ), "PYTHONPATH": agent_dir}
|
||||||
|
|
||||||
if catalog_id == "daily-briefing":
|
if catalog_id == "daily-briefing":
|
||||||
# Find the user's briefing wrapper script or use the generic engine
|
script_map = {"eric": "eric_briefing.py", "angela": "angela_briefing.py"}
|
||||||
import subprocess
|
|
||||||
env = {**dict(os.environ), f"{u.username.upper().replace('.','_')}_INSTANCE_ID": str(instance_id)}
|
|
||||||
# Check for user-specific script
|
|
||||||
script_map = {
|
|
||||||
"eric": "eric_briefing.py",
|
|
||||||
"angela": "angela_briefing.py",
|
|
||||||
}
|
|
||||||
script = script_map.get(u.username, None)
|
script = script_map.get(u.username, None)
|
||||||
|
env_key = f"{u.username.upper().replace('.', '_')}_INSTANCE_ID"
|
||||||
|
env[env_key] = str(instance_id)
|
||||||
if script:
|
if script:
|
||||||
cmd = f"cd /opt/agent-dashboard/agents && {u.username.upper().replace('.','_')}_INSTANCE_ID={instance_id} python3 {script}"
|
cmd = ["python3", f"{agent_dir}/{script}"]
|
||||||
else:
|
else:
|
||||||
cmd = f"cd /opt/agent-dashboard/agents && python3 -c \"from daily_briefing import run; run({{'person': '{u.display_name}', 'agent_id': '{catalog_id}', 'instance_id': {instance_id}, 'wiki_parent_doc_id': '', 'location': {{}}}})\""
|
# Generic: run the engine directly with instance config
|
||||||
subprocess.Popen(cmd, shell=True, env=env)
|
cmd = ["python3", "-c",
|
||||||
|
f"import sys; sys.path.insert(0, '{agent_dir}'); "
|
||||||
|
f"from daily_briefing import run; "
|
||||||
|
f"run({{'person': '{u.display_name}', 'agent_id': '{catalog_id}', "
|
||||||
|
f"'instance_id': {instance_id}, 'wiki_parent_doc_id': '', 'location': {{}}}})"]
|
||||||
|
subprocess.Popen(cmd, env=env, cwd=agent_dir)
|
||||||
return {"status": "triggered", "message": f"Running {catalog_id} for {u.display_name}"}
|
return {"status": "triggered", "message": f"Running {catalog_id} for {u.display_name}"}
|
||||||
|
|
||||||
return {"status": "error", "message": f"Manual trigger not supported for {catalog_id} yet"}
|
return {"status": "error", "message": f"Manual trigger not yet supported for {catalog_id}"}
|
||||||
|
|
||||||
|
|
||||||
# --- Internal endpoints (no auth, for agent scripts) ---
|
# --- Internal endpoints (no auth, for agent scripts) ---
|
||||||
@@ -756,7 +760,8 @@ def get_my_bridge(user: dict = Depends(require_auth), db: Session = Depends(get_
|
|||||||
return {"connected": False}
|
return {"connected": False}
|
||||||
# Mark offline if no heartbeat in 10 minutes
|
# Mark offline if no heartbeat in 10 minutes
|
||||||
if bridge.last_heartbeat:
|
if bridge.last_heartbeat:
|
||||||
age = (datetime.now(timezone.utc) - bridge.last_heartbeat).total_seconds()
|
hb = bridge.last_heartbeat.replace(tzinfo=timezone.utc) if bridge.last_heartbeat.tzinfo is None else bridge.last_heartbeat
|
||||||
|
age = (datetime.now(timezone.utc) - hb).total_seconds()
|
||||||
if age > 600:
|
if age > 600:
|
||||||
bridge.status = "offline"
|
bridge.status = "offline"
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ services:
|
|||||||
- "8550:8550"
|
- "8550:8550"
|
||||||
volumes:
|
volumes:
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
|
- ./agents:/app/agents
|
||||||
environment:
|
environment:
|
||||||
- DB_PATH=/app/data/agents.db
|
- DB_PATH=/app/data/agents.db
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
Reference in New Issue
Block a user