mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[mod] send jobs list during websocket initialisation
This commit is contained in:
parent
4ed5a01e8c
commit
754cbdec87
2 changed files with 8 additions and 5 deletions
5
run.py
5
run.py
|
@ -172,6 +172,11 @@ def subscribe(ws, channel):
|
|||
async def index_ws(request, websocket):
|
||||
subscribe(websocket, "jobs")
|
||||
|
||||
await websocket.send(ujson.dumps({
|
||||
"target": "init_jobs",
|
||||
"data": map(model_to_dict, Job.select()),
|
||||
}))
|
||||
|
||||
while True:
|
||||
data = await websocket.recv()
|
||||
print(f"websocket: {data}")
|
||||
|
|
|
@ -39,10 +39,6 @@
|
|||
},
|
||||
})
|
||||
|
||||
$.getJSON("/api/jobs").done(function(data) {
|
||||
app.jobs = data;
|
||||
})
|
||||
|
||||
ws = new WebSocket('ws://' + document.domain + ':' + location.port + '/index-ws');
|
||||
|
||||
ws.onmessage = function (event) {
|
||||
|
@ -50,7 +46,9 @@
|
|||
var data = message.data;
|
||||
var target = message.target;
|
||||
|
||||
if (target == "update_job") {
|
||||
if (target == "init_jobs") {
|
||||
app.jobs = data;
|
||||
} else if (target == "update_job") {
|
||||
for (var i = 0; i < app.jobs.length; ++i) {
|
||||
if (app.jobs[i].id == data.id) {
|
||||
Vue.set(app.jobs, i, data);
|
||||
|
|
Loading…
Add table
Reference in a new issue