05/24 Enhance functionalities
This commit is contained in:
@@ -3,10 +3,13 @@ routes/user_dashboard.py — Regular user: shift check dashboard.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import time
|
||||
import requests as _http_req
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, session, jsonify
|
||||
from models import (
|
||||
get_today_checks, mark_website_checked, unmark_website_checked,
|
||||
update_check_note, get_user_active_shifts, get_website_credentials,
|
||||
get_website_url,
|
||||
)
|
||||
from utils.decorators import login_required
|
||||
|
||||
@@ -91,3 +94,23 @@ def view_credentials(website_id):
|
||||
except Exception as e:
|
||||
logger.error(f"view_credentials error: {e}")
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
@user_dashboard_bp.route("/health/<int:website_id>")
|
||||
@login_required
|
||||
def health_check(website_id):
|
||||
"""Server-side HEAD probe for a website's reachability."""
|
||||
url = get_website_url(website_id)
|
||||
if not url:
|
||||
return jsonify({"status": "not_found"}), 404
|
||||
try:
|
||||
t0 = time.time()
|
||||
resp = _http_req.head(url, timeout=6, allow_redirects=True,
|
||||
headers={"User-Agent": "WebsiteChecker/1.0 (health-check)"})
|
||||
ms = int((time.time() - t0) * 1000)
|
||||
ok = resp.status_code < 400
|
||||
return jsonify({"status": "ok" if ok else "error", "ms": ms})
|
||||
except _http_req.exceptions.Timeout:
|
||||
return jsonify({"status": "timeout", "ms": 6000})
|
||||
except Exception:
|
||||
return jsonify({"status": "unreachable", "ms": None})
|
||||
|
||||
Reference in New Issue
Block a user