API endpoint to get AWS Batch jobs with caching (2 min timeout) Concurrent requests are coalesced to prevent multiple simultaneous AWS API calls.
()
| 1409 | @app.route("/batch/api/jobs") |
| 1410 | @print_timing |
| 1411 | def batch_api_jobs(): |
| 1412 | """API endpoint to get AWS Batch jobs with caching (2 min timeout) |
| 1413 | |
| 1414 | Concurrent requests are coalesced to prevent multiple simultaneous AWS API calls. |
| 1415 | """ |
| 1416 | # Don't show batch API in static mode - skip freezing |
| 1417 | if STATIC_MODE: |
| 1418 | return redirect(url_for("index")) |
| 1419 | |
| 1420 | try: |
| 1421 | hours_back = request.args.get("hours_back", default=24, type=int) |
| 1422 | force_refresh = request.args.get("force_refresh", default="false", type=str).lower() == "true" |
| 1423 | |
| 1424 | cache_key = f"batch_jobs:{hours_back}" |
| 1425 | |
| 1426 | # If force_refresh is true, invalidate cache |
| 1427 | if force_refresh: |
| 1428 | _cache.invalidate(cache_key) |
| 1429 | logger.info("Force refresh requested, invalidating batch jobs cache") |
| 1430 | |
| 1431 | # Use get_or_compute to prevent concurrent AWS API calls |
| 1432 | def compute(): |
| 1433 | try: |
| 1434 | return _fetch_batch_jobs_impl(hours_back) |
| 1435 | except TimeoutError: |
| 1436 | logger.error("Timeout while fetching AWS Batch jobs") |
| 1437 | raise # Re-raise to be caught by outer handler |
| 1438 | |
| 1439 | result = _cache.get_or_compute(cache_key, compute, timeout_seconds=120) |
| 1440 | return jsonify({"success": True, **result}) |
| 1441 | except TimeoutError: |
| 1442 | logger.error("Timeout while fetching AWS Batch jobs") |
| 1443 | return jsonify({"success": False, "error": "Request timed out after 2 minutes"}), 504 |
| 1444 | except Exception as e: |
| 1445 | logger.error(f"Error fetching AWS Batch jobs: {e}", exc_info=True) |
| 1446 | return jsonify({"success": False, "error": str(e)}), 500 |
| 1447 | |
| 1448 | |
| 1449 | @app.route("/picker/api/guess-config-names", methods=["POST"]) |
nothing calls this directly
no test coverage detected