From f6ff9dca8330f6d0579dc88cec9ac9e827a2ff03 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 3 Nov 2018 20:18:24 +0100 Subject: [PATCH] [enh] broadcast new app event --- run.py | 6 ++++++ templates/apps.html | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/run.py b/run.py index f90beb0..7b48dc1 100644 --- a/run.py +++ b/run.py @@ -242,6 +242,11 @@ async def monitor_apps_lists(type="stable"): random_job_day=random.randint(1, 28), ) + await broadcast({ + "action": "new_app", + "data": model_to_dict(repo), + }, "apps") + await create_job(app_id, app_list_name, repo, job_command_last_part) await asyncio.sleep(3) @@ -454,6 +459,7 @@ async def ws_job(request, websocket, job_id): @app.websocket('/apps-ws') async def ws_apps(request, websocket): subscribe(websocket, "jobs") + subscribe(websocket, "apps") # I need to do this because peewee strangely fuck up on join and remove the # subquery fields which breaks everything diff --git a/templates/apps.html b/templates/apps.html index 9ab9e7f..866c25b 100644 --- a/templates/apps.html +++ b/templates/apps.html @@ -76,6 +76,25 @@ if (action == "init_apps") { app.apps = data; + } else if (action == "new_app") { + for (var i = 0; i < app.apps.length; ++i) { + if (data.name < app.apps[i].name) { + break; + } + } + + // I need to set everything as null then a first job should be + // created right after the app + app.apps.splice(i, 0, Object.assign(data, { + "job_id": null, + "job_name": null, + "url_or_path": null, + "job_state": null, + "log": null, + "created_time": null, + "started_time": null, + "end_time": null, + })); } else if (action == "update_job") { for (var i = 0; i < app.apps.length; ++i) { if (app.apps[i].job_id == data.id) {