diff --git a/run.py b/run.py
index cf99d5b..72f4c80 100644
--- a/run.py
+++ b/run.py
@@ -2,6 +2,7 @@
import os
import sys
+import ujson
import asyncio
import random
@@ -15,6 +16,8 @@ from websockets.exceptions import ConnectionClosed
from sanic import Sanic, response
+from playhouse.shortcuts import model_to_dict, dict_to_model
+
from models import Repo, BuildTask, db
app = Sanic()
@@ -100,7 +103,11 @@ async def run_jobs():
build_task.end_time = datetime.now()
build_task.save()
- await broadcast_to_ws(all_index_ws, f"done for {build_task.repo.name}")
+ await broadcast_to_ws(all_index_ws, {
+ "target": "build_task",
+ "id": build_task.id,
+ "data": model_to_dict(build_task),
+ })
await asyncio.sleep(3)
@@ -110,13 +117,14 @@ async def broadcast_to_ws(ws_list, message):
for ws in ws_list:
try:
- await ws.send(message)
+ await ws.send(ujson.dumps(message))
except ConnectionClosed:
dead_ws.append(ws)
for to_remove in dead_ws:
ws_list.remove(to_remove)
+
@app.websocket('/index-ws')
async def index_ws(request, websocket):
all_index_ws.append(websocket)
@@ -126,6 +134,11 @@ async def index_ws(request, websocket):
await websocket.send(f"echo {data}")
+@app.route("/api/tasks")
+async def api_tasks(request):
+ return response.json(map(model_to_dict, BuildTask.select()))
+
+
@app.route('/')
async def index(request):
return response.html(open("./templates/index.html", "r").read())
diff --git a/templates/index.html b/templates/index.html
index f27017b..be781ab 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -1,37 +1,64 @@
+
+ YunoRunner for CI
+
+
+
Tasks
-
-
- App |
- State |
- Revision |
- Ynh Version |
- Created time |
- Started time |
- End time |
-
- {% for build_task in build_tasks %}
-
- {{build_task.repo.name}} |
- {{build_task.state}} |
- {{build_task.target_revision}} |
- {{build_task.yunohost_version}} |
- {{build_task.created_time}} |
- {{build_task.started_time}} |
- {{build_task.end_time}} |
-
- {% endfor %}
-
+
+
+
+ App |
+ State |
+ Revision |
+ Ynh Version |
+ Created time |
+ Started time |
+ End time |
+
+
+ {{build_task.repo.name}} |
+ {{build_task.state}} |
+ {{build_task.target_revision}} |
+ {{build_task.yunohost_version}} |
+ {{build_task.created_time}} |
+ {{build_task.started_time}} |
+ {{build_task.end_time}} |
+
+
+