[enh] broadcast new app event

This commit is contained in:
Laurent Peuch 2018-11-03 20:18:24 +01:00
parent 5e9a675921
commit f6ff9dca83
2 changed files with 25 additions and 0 deletions

6
run.py
View file

@ -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

View file

@ -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) {