feat: notificaction service completo
This commit is contained in:
@@ -246,4 +246,31 @@ def startup():
|
||||
# Arranca el cron en background
|
||||
t = threading.Thread(target=start_cron, daemon=True)
|
||||
t.start()
|
||||
print(f"[STARTUP] Notification Service listo. {len(RUTAS)} rutas cargadas.")
|
||||
print(f"[STARTUP] Notification Service listo. {len(RUTAS)} rutas cargadas.")
|
||||
|
||||
@app.post("/internal/reset")
|
||||
def reset_routes():
|
||||
"""Reinicia todas las rutas a positionId 1. Útil para el demo."""
|
||||
for route_id in RUTAS:
|
||||
route_state[route_id] = {"positionId": 1, "notified": set()}
|
||||
print("[RESET] Todas las rutas reiniciadas a positionId 1")
|
||||
return {"status": "ok", "message": f"{len(RUTAS)} rutas reiniciadas"}
|
||||
|
||||
@app.post("/internal/demo")
|
||||
def demo_trigger(payload: dict):
|
||||
"""
|
||||
Fuerza una ruta a un positionId específico al instante.
|
||||
Ideal para demos en vivo.
|
||||
Body: { "routeId": "RUTA-01", "positionId": 4 }
|
||||
"""
|
||||
route_id = payload.get("routeId", "RUTA-01")
|
||||
position_id = payload.get("positionId", 4)
|
||||
|
||||
# Limpia notificaciones previas para que dispare de nuevo
|
||||
state = route_state.setdefault(route_id, {"positionId": 1, "notified": set()})
|
||||
state["notified"].discard("ROUTE_START")
|
||||
state["notified"].discard("TRUCK_PROXIMITY")
|
||||
state["notified"].discard("ROUTE_COMPLETED")
|
||||
|
||||
process_position_update(route_id, position_id)
|
||||
return {"status": "ok", "routeId": route_id, "positionId": position_id}
|
||||
Reference in New Issue
Block a user