Files
Juan Denis d134af25ae Drop route try/excepts the 500 handler duplicates
33 routes wrapped their body in try/except Exception only to return
unexpected_response(e), which records the crash and answers the same
body the global 500 handler already does. Every site was directly in a
route function, so the handler sees the same exceptions. SAML metadata
relied on its wrapper for an unconfigured IdP; that is now a typed 404
instead of a logged crash on a public, probed route.
2026-10-10 18:14:28 -04:00

30 lines
1.0 KiB
Python

"""REST surface for the on-demand server speed test.
Mounted at /api/v1/speedtest (registered in app/__init__.py).
"""
from flask import Blueprint, jsonify
from ..middleware.rbac import admin_required, viewer_required
from ..services.speed_test_service import SPEEDTEST_JOB_KIND, SpeedTestService
speedtest_bp = Blueprint('speedtest', __name__)
@speedtest_bp.route('', methods=['GET'])
@speedtest_bp.route('/', methods=['GET'])
@viewer_required
def get_speed_test():
"""Last stored result + status of any in-flight speed test job."""
return jsonify(SpeedTestService.get_status())
@speedtest_bp.route('/run', methods=['POST'])
@admin_required
def run_speed_test():
"""Enqueue a one-off speed test job. Rejects if one is already in flight."""
if SpeedTestService.is_running():
return jsonify({'error': 'A speed test is already in progress.'}), 409
from app.jobs.service import JobService
job = JobService.enqueue(SPEEDTEST_JOB_KIND, payload={}, max_attempts=1)
return jsonify({'job_id': job.id}), 202