28 lines
893 B
Python
28 lines
893 B
Python
from flask import Blueprint, request, jsonify
|
|
from auth import require_level
|
|
from config_utils import (
|
|
_load_done_set, _is_locked, _lock_mtime,
|
|
_seconds_until_next_run, _entry_ts_from_queue,
|
|
)
|
|
|
|
bp = Blueprint('api_apply_health', __name__)
|
|
|
|
|
|
@bp.route('/api/apply-health')
|
|
@require_level('viewer')
|
|
def apply_health():
|
|
entry_uuid = request.args.get('uuid', '')
|
|
if not entry_uuid:
|
|
return jsonify({'status': 'unknown'})
|
|
|
|
if entry_uuid in _load_done_set():
|
|
return jsonify({'status': 'complete'})
|
|
|
|
if _is_locked():
|
|
mtime = _lock_mtime()
|
|
entry_ts = _entry_ts_from_queue(entry_uuid)
|
|
if mtime and entry_ts is not None and entry_ts < mtime:
|
|
return jsonify({'status': 'running'})
|
|
return jsonify({'status': 'pending', 'next_in': None})
|
|
|
|
return jsonify({'status': 'pending', 'next_in': _seconds_until_next_run()})
|