Skip to content
Snippets Groups Projects
Commit 9d860562 authored by Julian Rother's avatar Julian Rother
Browse files

Implemented edit_handler and job_handler

parent 1d405391
No related branches found
No related tags found
No related merge requests found
......@@ -119,6 +119,18 @@ def getfielddescription(path):
desc = '<br>'+desc
return desc
edit_handlers = {}
def edit_handler(*tables, field=None):
def wrapper(func):
for table in tables:
if table not in edit_handlers:
edit_handlers[table] = {}
if field not in edit_handlers[table]:
edit_handlers[table][field] = []
edit_handlers[table][field].append(func)
return func
return wrapper
@app.route('/internal/edit', methods=['GET', 'POST'])
@mod_required
@csrf_protect
......@@ -141,6 +153,10 @@ def edit(prefix='', ignore=[]):
VALUES (?,?,?,?,?,(SELECT `%s` FROM %s WHERE %s = ?),?,?,1)'%(path['column'], path['tableinfo']['table'], path['tableinfo']['idcolumn']),
path['table'], path['id'], path['tableinfo']['idcolumn'], path['column'], val, path['id'], datetime.now(), session['user']['dbid'])
modify('UPDATE %s SET `%s` = ?, time_updated = ? WHERE `%s` = ?'%(path['tableinfo']['table'], path['column'], path['tableinfo']['idcolumn']), val, datetime.now(),path['id'])
for func in edit_handlers.get(path['table'], {}).get(None, []):
func(path['table'], path['column'], val, path['id'])
for func in edit_handlers.get(path['table'], {}).get(path['column'], []):
func(path['table'], path['column'], val, path['id'])
if 'ref' in request.values:
return redirect(request.values['ref'])
return "OK", 200
......
......@@ -67,7 +67,7 @@ def jobs_api_token_required(func):
else:
token = None
if not token == config['JOBS_API_KEY']:
if not token == config.get('JOBS_API_KEY', [None]):
return 'Permission denied', 403
else:
return func(*args, **kwargs)
......@@ -99,6 +99,25 @@ def jobs_worker_ping(hostname):
query('REPLACE INTO worker (hostname, last_ping) values (?, ?)', hostname, datetime.now())
return 'OK',200
job_handlers = {}
def job_handler(*types, state='finished'):
def wrapper(func):
for jobtype in types:
if jobtype not in job_handlers:
job_handlers[jobtype] = {}
if jobtype not in job_handlers[jobtype]:
job_handlers[jobtype][state] = []
job_handlers[jobtype][state].append(func)
return func
return wrapper
def schedule_job(jobtype, data=None, priority=0):
if not data:
data = {}
modify('INSERT INTO jobs (type, priority, data, time_created) VALUES (?, ?, ?, ?)',
jobtype, priority, json.dumps(data, default=date_json_handler), datetime.now())
@app.route('/internal/jobs/api/job/<int:id>/ping', methods=['GET', 'POST'])
@jobs_api_token_required
def jobs_ping(id):
......@@ -109,6 +128,12 @@ def jobs_ping(id):
query('UPDATE jobs SET time_finished = ?, status = ?, state = "finished" where id = ?', datetime.now(), status, id)
else:
query('UPDATE jobs SET worker = ?, last_ping = ?, status = ?, state = ? where id = ?', hostname, datetime.now(), status, state, id)
job = query('SELECT * FROM jobs WHERE id = ?', id)[0]
for func in job_handlers.get(job['type'], {}).get(state, []):
try:
func(id, job['type'], json.loads(job['data']), state, json.loads(job['status']))
except Exception:
traceback.print_exc()
return 'OK', 200
@app.route('/internal/jobs/api/worker/<hostname>/schedule', methods=['POST'])
......
......@@ -461,7 +461,7 @@ def dbstatus():
clusters[cluster].append(host)
return render_template('dbstatus.html', clusters=clusters, statuses=status, vars=variables), 200
import edit
from edit import edit_handler
import feeds
import importer
import stats
......@@ -469,8 +469,7 @@ import sorter
if 'ICAL_URL' in config:
import meetings
import l2pauth
if 'JOBS_API_KEY' in config:
import jobs
from jobs import job_handler, schedule_job
import timetable
import chapters
import icalexport
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment