Skip to content
Merged

web #415

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 148 additions & 51 deletions selfdrive/carrot/README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions selfdrive/carrot/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .services.git_status import git_status_loop
from .services.heartbeat import heartbeat_loop
from .services.params import HAS_PARAMS
from .services.popular_values import start_popular_value_upload

VISION_DIAG_UPLOAD_MAX_BYTES = 16 * 1024 * 1024

Expand Down Expand Up @@ -85,6 +86,7 @@ async def on_startup(app: web.Application) -> None:
app["hb_task"] = asyncio.create_task(heartbeat_loop(app))
app["git_status_task"] = asyncio.create_task(git_status_loop())
app["auto_update_task"] = asyncio.create_task(auto_update_loop())
app["popular_value_upload_task"] = start_popular_value_upload(app)
asyncio.create_task(_malloc_trim_loop())


Expand Down Expand Up @@ -133,6 +135,16 @@ async def on_cleanup(app: web.Application) -> None:
except Exception:
pass

popular_value_upload_task = app.get("popular_value_upload_task")
if popular_value_upload_task:
popular_value_upload_task.cancel()
try:
await popular_value_upload_task
except asyncio.CancelledError:
pass
except Exception:
pass

sess = app.get("http")
if sess:
await sess.close()
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/carrot/server/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
screenrecord,
settings,
setting_favorites,
setting_popular_values,
setting_profiles,
ssh_keys,
static,
Expand All @@ -28,6 +29,7 @@ def register_all(app: web.Application) -> None:
settings.register(app)
params.register(app)
setting_favorites.register(app)
setting_popular_values.register(app)
setting_profiles.register(app)
web_settings.register(app)
ssh_keys.register(app)
Expand Down
43 changes: 43 additions & 0 deletions selfdrive/carrot/server/features/setting_popular_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from __future__ import annotations

from aiohttp import web

from ..services.popular_values import (
get_popular_value_detail,
read_popular_values_memory,
refresh_popular_values_once,
schedule_popular_value_refresh,
)


async def api_setting_popular_values(request: web.Request) -> web.Response:
# Kick a throttled, download-only refresh so opening settings reflects the
# latest fleet values (non-blocking — returns the current cache immediately).
schedule_popular_value_refresh(request.app)
return web.json_response(read_popular_values_memory())


async def api_setting_popular_value_detail(request: web.Request) -> web.Response:
name = request.query.get("name", "")
cache = read_popular_values_memory()
return web.json_response({
"ok": True,
"car_key_type": cache.get("car_key_type", "CarSelected3"),
"car_key": cache.get("car_key", ""),
"param_name": name,
"detail": get_popular_value_detail(name),
})


async def api_setting_popular_values_refresh(request: web.Request) -> web.Response:
session = request.app.get("http")
if session is None:
return web.json_response(read_popular_values_memory())
cache = await refresh_popular_values_once(session, upload=True)
return web.json_response(cache)


def register(app: web.Application) -> None:
app.router.add_get("/api/setting_popular_values", api_setting_popular_values)
app.router.add_get("/api/setting_popular_values/detail", api_setting_popular_value_detail)
app.router.add_post("/api/setting_popular_values/refresh", api_setting_popular_values_refresh)
Loading
Loading