Skip to content

Commit

Permalink
Ak/handle ws disconnect (#44)
Browse files Browse the repository at this point in the history
* handle ws disconnects and also test new build fail if version isn't bumped

* fix dupe suffix
  • Loading branch information
akshaya-a authored Apr 17, 2024
1 parent 8e097b4 commit 6147abb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/addon-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
changed=$(echo ${changed_addons[@]} | rev | cut -c 2- | rev)
if [[ -n ${changed} ]]; then
if [[ ! "${{ steps.changed_files.outputs.all }}" =~ "config.yaml" ]]; then
echo "Error: config.yaml has not been changed but the add-on has been. Please update the version"
exit 1
fi
echo "Changed add-ons: $changed";
echo "changed=true" >> $GITHUB_OUTPUT;
echo "addons=[$changed]" >> $GITHUB_OUTPUT;
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/hassfest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: Validate with hassfest

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * *"

Expand Down
3 changes: 2 additions & 1 deletion addons/mindctrl/rootfs/usr/bin/run_dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ bashio::log.info "ingress_entry: ${ingress_entry}"
# Am I going to do it anyway? Yes.
# https://github.com/dapr/dashboard/blob/a92b8cd20d97080f07518ced9a5e8d0a58168ad9/cmd/webserver.go#L148C47-L148C63
if [[ -n "$ingress_entry" ]]; then
export SERVER_BASE_HREF="${ingress_entry}/dapr-dashboard/dapr-dashboard/"
# This trailing slash is important
export SERVER_BASE_HREF="${ingress_entry}/dapr-dashboard/"
bashio::log.info "running dashboard with prefix $SERVER_BASE_HREF"
fi

Expand Down
7 changes: 2 additions & 5 deletions python/src/mindctrl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import collections

from fastapi.templating import Jinja2Templates
import mlflow


Expand All @@ -22,7 +21,8 @@
from .db.setup import setup_db, insert_summary
from .config import AppSettings
from .routers import deployed_models, info, ui
from .const import ROUTE_PREFIX, TEMPLATES_DIR
from .routers.ui import templates
from .const import ROUTE_PREFIX


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -109,9 +109,6 @@ async def lifespan(app: FastAPI):
# return RedirectResponse(url=f"{ROUTE_PREFIX}/ui/", status_code=302)


templates = Jinja2Templates(directory=TEMPLATES_DIR)


@app.get("/")
def read_root(request: Request, response_class=HTMLResponse):
_logger.info(
Expand Down
40 changes: 4 additions & 36 deletions python/src/mindctrl/routers/ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import logging

from fastapi import APIRouter, WebSocket
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
from fastapi.templating import Jinja2Templates


Expand All @@ -16,41 +16,6 @@
templates = Jinja2Templates(directory=TEMPLATES_DIR)


# @router.get("/")
# def read_root(request: Request, response_class=HTMLResponse):
# ingress_header = request.headers.get("X-Ingress-Path")
# _logger.info(f"ingress path: {ingress_header}")

# ws_url = (
# f"{ingress_header}/ws"
# if ingress_header
# else f"{request.url_for('websocket_endpoint')}"
# )
# ingress_header = ingress_header or ""
# chat_url = f"{ingress_header}/deployed-models/chat/labels/latest/invocations"
# mlflow_url = request.base_url.replace(port=5000)
# _logger.info(f"mlflow url: {mlflow_url}")
# mlflow_url = f"{mlflow_url}/mlflow"
# _logger.info(f"mlflow url: {mlflow_url}")
# dashboard_url = request.base_url.replace(port=9999)
# _logger.info(f"dapr dashboard: {dashboard_url}")
# _logger.info(f"root_path: {request.scope.get('root_path')}")

# return templates.TemplateResponse(
# request=request,
# name="index.html",
# context={
# "request": request,
# "tracking_store": mlflow.get_tracking_uri(),
# "model_registry": mlflow.get_registry_uri(),
# "ws_url": ws_url,
# "chat_url": chat_url,
# "mlflow_url": mlflow_url,
# "dashboard_url": dashboard_url,
# },
# )


@router.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
Expand All @@ -66,3 +31,6 @@ async def websocket_endpoint(websocket: WebSocket):
_logger.warning("Websocket buffer empty, waiting for new events")
await asyncio.sleep(2)
ring_buffer = iter(websocket.state.state_ring_buffer.copy())
except WebSocketDisconnect:
_logger.warning("Websocket disconnected")
break

0 comments on commit 6147abb

Please sign in to comment.