mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[enh] add a page per job
This commit is contained in:
parent
d238efe612
commit
f0c5e9c597
2 changed files with 38 additions and 2 deletions
36
run.py
36
run.py
|
@ -16,6 +16,7 @@ import aiofiles
|
||||||
from websockets.exceptions import ConnectionClosed
|
from websockets.exceptions import ConnectionClosed
|
||||||
|
|
||||||
from sanic import Sanic, response
|
from sanic import Sanic, response
|
||||||
|
from sanic.exceptions import NotFound
|
||||||
|
|
||||||
from playhouse.shortcuts import model_to_dict, dict_to_model
|
from playhouse.shortcuts import model_to_dict, dict_to_model
|
||||||
|
|
||||||
|
@ -182,6 +183,28 @@ async def index_ws(request, websocket):
|
||||||
await websocket.send(f"echo {data}")
|
await websocket.send(f"echo {data}")
|
||||||
|
|
||||||
|
|
||||||
|
@app.websocket('/job-<job_id>-ws')
|
||||||
|
async def job_ws(request, websocket, job_id):
|
||||||
|
job = Job.select().where(Job.id == job_id)
|
||||||
|
|
||||||
|
if job.count == 0:
|
||||||
|
raise NotFound()
|
||||||
|
|
||||||
|
job = job[0]
|
||||||
|
|
||||||
|
subscribe(websocket, f"job-{job.id}")
|
||||||
|
|
||||||
|
await websocket.send(ujson.dumps({
|
||||||
|
"action": "init_job",
|
||||||
|
"data": model_to_dict(job),
|
||||||
|
}))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data = await websocket.recv()
|
||||||
|
print(f"websocket: {data}")
|
||||||
|
await websocket.send(f"echo {data}")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/jobs")
|
@app.route("/api/jobs")
|
||||||
async def api_jobs(request):
|
async def api_jobs(request):
|
||||||
return response.json(map(model_to_dict, Job.select()))
|
return response.json(map(model_to_dict, Job.select()))
|
||||||
|
@ -212,6 +235,19 @@ async def api_new_job(request):
|
||||||
return response.text("ok")
|
return response.text("ok")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/job/<job_id>')
|
||||||
|
async def job(request, job_id):
|
||||||
|
job = Job.select().where(Job.id == job_id)
|
||||||
|
|
||||||
|
if job.count == 0:
|
||||||
|
raise NotFound()
|
||||||
|
|
||||||
|
job = job[0]
|
||||||
|
|
||||||
|
async with aiofiles.open("./templates/job.html", mode="r") as index_template:
|
||||||
|
return response.html(await index_template.read() % job.id)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
async def index(request):
|
async def index(request):
|
||||||
async with aiofiles.open("./templates/index.html", mode="r") as index_template:
|
async with aiofiles.open("./templates/index.html", mode="r") as index_template:
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
<th>Started time</th>
|
<th>Started time</th>
|
||||||
<th>End time</th>
|
<th>End time</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-for="job in jobs" :id="job.id">
|
<tr v-for="(job, index) in jobs" :id="job.id">
|
||||||
<td>{{job.name}}</td>
|
<td><a v-bind:href="'/job/' + job.id">{{job.name}}</a></td>
|
||||||
<td>{{job.state}}</td>
|
<td>{{job.state}}</td>
|
||||||
<td>{{job.target_revision}}</td>
|
<td>{{job.target_revision}}</td>
|
||||||
<td>{{job.yunohost_version}}</td>
|
<td>{{job.yunohost_version}}</td>
|
||||||
|
|
Loading…
Add table
Reference in a new issue