mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[enh] start to work on api listing
This commit is contained in:
parent
4b9b1ff98e
commit
c4bda46189
2 changed files with 26 additions and 2 deletions
17
cli.py
17
cli.py
|
@ -45,7 +45,8 @@ def request_api(path, domain, verb, data):
|
||||||
|
|
||||||
# TODO: real error message
|
# TODO: real error message
|
||||||
assert response.status_code == 200, response.content
|
assert response.status_code == 200, response.content
|
||||||
assert response.content == b"ok", response.content
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def add(name, url_or_path, test_type="stable", yunohost_version="unstable", debian_version="stretch", revision="master", domain=DOMAIN):
|
def add(name, url_or_path, test_type="stable", yunohost_version="unstable", debian_version="stretch", revision="master", domain=DOMAIN):
|
||||||
|
@ -65,7 +66,19 @@ def add(name, url_or_path, test_type="stable", yunohost_version="unstable", debi
|
||||||
|
|
||||||
|
|
||||||
@named("list")
|
@named("list")
|
||||||
def list_(all=False, domain=DOMAIN): pass
|
def list_(all=False, domain=DOMAIN):
|
||||||
|
response = request_api(
|
||||||
|
path="job",
|
||||||
|
verb="get",
|
||||||
|
domain=domain,
|
||||||
|
data={
|
||||||
|
"all": all,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
for i in response.json():
|
||||||
|
print(f"{i['id']:4d} - {i['name']}")
|
||||||
|
|
||||||
def delete(job_id, domain=DOMAIN): pass
|
def delete(job_id, domain=DOMAIN): pass
|
||||||
def update(job_id, domain=DOMAIN): pass
|
def update(job_id, domain=DOMAIN): pass
|
||||||
def cancel(job_id, domain=DOMAIN): pass
|
def cancel(job_id, domain=DOMAIN): pass
|
||||||
|
|
11
run.py
11
run.py
|
@ -384,6 +384,17 @@ async def api_new_job(request):
|
||||||
return response.text("ok")
|
return response.text("ok")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/api/job", methods=['GET'])
|
||||||
|
@require_token()
|
||||||
|
async def api_list_job(request):
|
||||||
|
query = Job.select()
|
||||||
|
|
||||||
|
if not all:
|
||||||
|
query.where(Job.state in ('scheduled', 'running'))
|
||||||
|
|
||||||
|
return response.json([model_to_dict(x) for x in query.order_by(-Job.id)])
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/job/<job_id>/stop", methods=['POST'])
|
@app.route("/api/job/<job_id>/stop", methods=['POST'])
|
||||||
async def api_stop_job(request, job_id):
|
async def api_stop_job(request, job_id):
|
||||||
# TODO auth or some kind
|
# TODO auth or some kind
|
||||||
|
|
Loading…
Add table
Reference in a new issue