Commit 00595393 authored by Andreas Valder's avatar Andreas Valder
Browse files

added ping and schedule api

parent aea98511
from server import *
import traceback
import json
import random
@app.route('/jobs/overview')
@register_navbar('Jobs', iconlib='fa', icon='suitcase')
......@@ -31,11 +32,18 @@ def date_json_handler(obj):
@app.route('/jobs/api/ping', methods=['GET', 'POST'])
@jobs_api_token_required
def jobs_ping():
def jobs_worker_ping():
hostname = request.values['host']
query('INSERT OR REPLACE INTO worker (hostname, last_ping) values (?, ?)',hostname,datetime.now())
return 'OK',200
@app.route('/jobs/api/job/<id>/ping', methods=['GET', 'POST'])
@jobs_api_token_required
def jobs_ping(id):
hostname = request.values['host']
query('UPDATE jobs SET worker = ?, last_ping = ? where id = ?',hostname,datetime.now(),id)
return 'OK',200
@app.route('/jobs/api/schedule', methods=['POST'])
@jobs_api_token_required
def jobs_schedule():
......@@ -43,9 +51,18 @@ def jobs_schedule():
print(hostdata)
if not hostdata:
return 'no data', 500
job = None
jobtypes = hostdata['jobtypes'] if 'jobtypes' in hostdata else []
while (not job):
query("BEGIN")
for i in query('SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'):
if i['type'] in hostdata['jobtypes'].split(','):
job=i
break
modify('UPDATE jobs SET state="running", worker = ? WHERE id = ?', hostdata['host'], job['id'])
try:
query("COMMIT")
except:
job = None
sleep(random.randinti(0,50))
return Response(json.dumps(job, default=date_json_handler), mimetype='application/json')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment