Skip to content

Commit 5b0a357

Browse files
author
Andrei Neagu
committed
replaced ui engine
1 parent 3f8115c commit 5b0a357

File tree

18 files changed

+170
-531
lines changed

18 files changed

+170
-531
lines changed

.env-devel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ AGENT_VOLUMES_CLEANUP_S3_REGION=us-east-1
1919
AGENT_VOLUMES_CLEANUP_S3_SECRET_KEY=12345678
2020
AGENT_TRACING={}
2121

22+
2223
API_SERVER_DEV_FEATURES_ENABLED=0
2324
API_SERVER_LOGLEVEL=INFO
2425
API_SERVER_PROFILING=1
@@ -128,6 +129,7 @@ DYNAMIC_SCHEDULER_LOGLEVEL=DEBUG
128129
DYNAMIC_SCHEDULER_PROFILING=1
129130
DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT=01:00:00
130131
DYNAMIC_SCHEDULER_TRACING={}
132+
DYNAMIC_SCHEDULER_UI_STORAGE_SECRET=c411085b-a75e-4a38-aa37-f085c91c3371
131133

132134
FUNCTION_SERVICES_AUTHORS='{"UN": {"name": "Unknown", "email": "[email protected]", "affiliation": "unknown"}}'
133135

services/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ services:
567567
DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT: ${DYNAMIC_SCHEDULER_STOP_SERVICE_TIMEOUT}
568568
DYNAMIC_SCHEDULER_PROFILING: ${DYNAMIC_SCHEDULER_PROFILING}
569569
DYNAMIC_SCHEDULER_TRACING: ${DYNAMIC_SCHEDULER_TRACING}
570+
DYNAMIC_SCHEDULER_UI_STORAGE_SECRET: ${DYNAMIC_SCHEDULER_UI_STORAGE_SECRET}
570571
TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT: ${TRACING_OPENTELEMETRY_COLLECTOR_ENDPOINT}
571572
TRACING_OPENTELEMETRY_COLLECTOR_PORT: ${TRACING_OPENTELEMETRY_COLLECTOR_PORT}
572573
static-webserver:

services/dynamic-scheduler/requirements/_base.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
arrow
1919
fastapi
20-
fastui
2120
httpx
21+
nicegui
2222
packaging
2323
python-socketio
2424
typer[all]

services/dynamic-scheduler/requirements/_base.txt

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ aiodebug==2.3.0
77
aiodocker==0.23.0
88
# via -r requirements/../../../packages/service-library/requirements/_base.in
99
aiofiles==24.1.0
10-
# via -r requirements/../../../packages/service-library/requirements/_base.in
10+
# via
11+
# -r requirements/../../../packages/service-library/requirements/_base.in
12+
# nicegui
1113
aiohappyeyeballs==2.4.3
1214
# via aiohttp
1315
aiohttp==3.10.10
@@ -27,6 +29,8 @@ aiohttp==3.10.10
2729
# -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
2830
# -c requirements/../../../requirements/constraints.txt
2931
# aiodocker
32+
# nicegui
33+
# python-socketio
3034
aiormq==6.8.1
3135
# via aio-pika
3236
aiosignal==1.3.1
@@ -79,6 +83,7 @@ certifi==2024.8.30
7983
# -c requirements/../../../requirements/constraints.txt
8084
# httpcore
8185
# httpx
86+
# nicegui
8287
# requests
8388
charset-normalizer==3.4.0
8489
# via requests
@@ -94,6 +99,8 @@ deprecated==1.2.14
9499
# opentelemetry-semantic-conventions
95100
dnspython==2.7.0
96101
# via email-validator
102+
docutils==0.21.2
103+
# via nicegui
97104
email-validator==2.2.0
98105
# via pydantic
99106
fast-depends==2.4.12
@@ -102,10 +109,9 @@ fastapi==0.115.5
102109
# via
103110
# -r requirements/../../../packages/service-library/requirements/_fastapi.in
104111
# -r requirements/_base.in
112+
# nicegui
105113
faststream==0.5.28
106114
# via -r requirements/../../../packages/service-library/requirements/_base.in
107-
fastui==0.7.0
108-
# via -r requirements/_base.in
109115
frozenlist==1.4.1
110116
# via
111117
# aiohttp
@@ -145,15 +151,37 @@ httpx==0.27.2
145151
# -c requirements/../../../requirements/constraints.txt
146152
# -r requirements/../../../packages/service-library/requirements/_fastapi.in
147153
# -r requirements/_base.in
154+
# nicegui
148155
idna==3.10
149156
# via
150157
# anyio
151158
# email-validator
152159
# httpx
153160
# requests
154161
# yarl
162+
ifaddr==0.2.0
163+
# via nicegui
155164
importlib-metadata==8.4.0
156165
# via opentelemetry-api
166+
itsdangerous==2.2.0
167+
# via nicegui
168+
jinja2==3.1.4
169+
# via
170+
# -c requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
171+
# -c requirements/../../../packages/models-library/requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
172+
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
173+
# -c requirements/../../../packages/postgres-database/requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
174+
# -c requirements/../../../packages/postgres-database/requirements/../../../requirements/constraints.txt
175+
# -c requirements/../../../packages/service-library/requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
176+
# -c requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
177+
# -c requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
178+
# -c requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
179+
# -c requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
180+
# -c requirements/../../../packages/service-library/requirements/../../../requirements/constraints.txt
181+
# -c requirements/../../../packages/settings-library/requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
182+
# -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
183+
# -c requirements/../../../requirements/constraints.txt
184+
# nicegui
157185
jsonschema==4.23.0
158186
# via
159187
# -r requirements/../../../packages/models-library/requirements/_base.in
@@ -179,14 +207,20 @@ mako==1.3.5
179207
# alembic
180208
markdown-it-py==3.0.0
181209
# via rich
210+
markdown2==2.5.1
211+
# via nicegui
182212
markupsafe==3.0.1
183-
# via mako
213+
# via
214+
# jinja2
215+
# mako
184216
mdurl==0.1.2
185217
# via markdown-it-py
186218
multidict==6.1.0
187219
# via
188220
# aiohttp
189221
# yarl
222+
nicegui==2.7.0
223+
# via -r requirements/_base.in
190224
opentelemetry-api==1.27.0
191225
# via
192226
# -r requirements/../../../packages/service-library/requirements/_base.in
@@ -281,6 +315,7 @@ orjson==3.10.7
281315
# -r requirements/../../../packages/service-library/requirements/../../../packages/models-library/requirements/_base.in
282316
# -r requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/../../../packages/common-library/requirements/_base.in
283317
# -r requirements/../../../packages/settings-library/requirements/../../../packages/common-library/requirements/_base.in
318+
# nicegui
284319
packaging==24.1
285320
# via -r requirements/_base.in
286321
pamqp==3.3.0
@@ -297,6 +332,8 @@ protobuf==4.25.5
297332
# via
298333
# googleapis-common-protos
299334
# opentelemetry-proto
335+
pscript==0.7.7
336+
# via vbuild
300337
psutil==6.0.0
301338
# via -r requirements/../../../packages/service-library/requirements/_base.in
302339
psycopg2-binary==2.9.10
@@ -332,7 +369,6 @@ pydantic==2.9.2
332369
# -r requirements/../../../packages/settings-library/requirements/_base.in
333370
# fast-depends
334371
# fastapi
335-
# fastui
336372
# pydantic-extra-types
337373
# pydantic-settings
338374
pydantic-core==2.23.4
@@ -355,7 +391,9 @@ pydantic-settings==2.6.1
355391
# -r requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/_base.in
356392
# -r requirements/../../../packages/settings-library/requirements/_base.in
357393
pygments==2.18.0
358-
# via rich
394+
# via
395+
# nicegui
396+
# rich
359397
pyinstrument==5.0.0
360398
# via -r requirements/../../../packages/service-library/requirements/_base.in
361399
python-dateutil==2.9.0.post0
@@ -366,8 +404,12 @@ python-dotenv==1.0.1
366404
# uvicorn
367405
python-engineio==4.10.1
368406
# via python-socketio
407+
python-multipart==0.0.17
408+
# via nicegui
369409
python-socketio==5.11.4
370-
# via -r requirements/_base.in
410+
# via
411+
# -r requirements/_base.in
412+
# nicegui
371413
pyyaml==6.0.2
372414
# via
373415
# -c requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
@@ -411,7 +453,9 @@ referencing==0.29.3
411453
repro-zipfile==0.3.1
412454
# via -r requirements/../../../packages/service-library/requirements/_base.in
413455
requests==2.32.3
414-
# via opentelemetry-exporter-otlp-proto-http
456+
# via
457+
# nicegui
458+
# opentelemetry-exporter-otlp-proto-http
415459
rich==13.9.2
416460
# via
417461
# -r requirements/../../../packages/service-library/requirements/../../../packages/settings-library/requirements/_base.in
@@ -488,6 +532,7 @@ typing-extensions==4.12.2
488532
# alembic
489533
# fastapi
490534
# faststream
535+
# nicegui
491536
# opentelemetry-sdk
492537
# pydantic
493538
# pydantic-core
@@ -510,15 +555,21 @@ urllib3==2.2.3
510555
# -c requirements/../../../packages/settings-library/requirements/../../../packages/common-library/requirements/../../../requirements/constraints.txt
511556
# -c requirements/../../../packages/settings-library/requirements/../../../requirements/constraints.txt
512557
# -c requirements/../../../requirements/constraints.txt
558+
# nicegui
513559
# requests
514560
uvicorn==0.32.0
515561
# via
516562
# -r requirements/../../../packages/service-library/requirements/_fastapi.in
517563
# -r requirements/_base.in
564+
# nicegui
518565
uvloop==0.21.0
519566
# via uvicorn
567+
vbuild==0.8.2
568+
# via nicegui
520569
watchfiles==0.24.0
521-
# via uvicorn
570+
# via
571+
# nicegui
572+
# uvicorn
522573
websockets==13.1
523574
# via uvicorn
524575
wrapt==1.16.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ._setup import setup_frontend
2+
3+
__all__: tuple[str, ...] = ("setup_frontend",)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from collections.abc import Iterator
2+
from contextlib import contextmanager
3+
4+
from nicegui import ui
5+
6+
7+
@contextmanager
8+
def base_page(*, title: str | None = None, colour: str = "#D3D3D3") -> Iterator[None]:
9+
display_title = (
10+
"Dynamic Scheduler" if title is None else f"Dynamic Scheduler - {title}"
11+
)
12+
ui.page_title(display_title)
13+
with ui.header(elevated=True).style(f"background-color: {colour}").classes(
14+
"items-center justify-between"
15+
):
16+
ui.label("HEADER")
17+
18+
yield None
19+
20+
with ui.footer().style(f"background-color: {colour}"):
21+
ui.label("FOOTER")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from fastapi import FastAPI
2+
from models_library.projects_nodes_io import NodeID
3+
from nicegui import APIRouter, app, ui
4+
from nicegui.element import Element
5+
6+
from ...services.service_tracker import TrackedServiceModel, get_all_tracked_services
7+
from ._common import base_page
8+
from ._utils import get_parent_app
9+
10+
router = APIRouter()
11+
12+
13+
def _render_card(
14+
card_container: Element, node_id: NodeID, service: TrackedServiceModel
15+
) -> None:
16+
with card_container: # noqa: SIM117
17+
with ui.card():
18+
ui.label(f"{node_id}")
19+
# TODO finish card
20+
ui.label(service.model_dump_json())
21+
22+
23+
async def _update_cards(parent_app: FastAPI, card_container) -> None:
24+
card_container.clear() # Clear the current cards
25+
26+
tracked_services = await get_all_tracked_services(parent_app)
27+
28+
for node_id, service in tracked_services.items():
29+
_render_card(card_container, node_id, service)
30+
31+
32+
# changed this form ui to router
33+
@router.page("/")
34+
async def main_page():
35+
parent_app = get_parent_app(app)
36+
37+
with base_page():
38+
39+
# Initial UI setup
40+
ui.label("Dynamic Item List")
41+
42+
card_container: Element = ui.row()
43+
44+
# render cards when page is loaded
45+
await _update_cards(parent_app, card_container)
46+
47+
# update card at a set interval
48+
ui.timer(1.0, lambda: _update_cards(parent_app, card_container))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import nicegui
2+
from fastapi import FastAPI
3+
4+
from ...core.settings import ApplicationSettings
5+
from . import _index
6+
from ._utils import set_parent_app
7+
8+
9+
def setup_frontend(app: FastAPI) -> None:
10+
settings: ApplicationSettings = app.state.settings
11+
12+
nicegui.app.include_router(_index.router)
13+
14+
nicegui.ui.run_with(
15+
app, mount_path="/", storage_secret=settings.DYNAMIC_SCHEDULER_UI_STORAGE_SECRET
16+
)
17+
set_parent_app(app)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import nicegui
2+
from fastapi import FastAPI
3+
4+
5+
def set_parent_app(parent_app: FastAPI) -> None:
6+
nicegui.app.state.parent_app = parent_app
7+
8+
9+
def get_parent_app(app: FastAPI) -> FastAPI:
10+
parent_app: FastAPI = app.state.parent_app
11+
return parent_app

services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/api/ui/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)