"feat: Integrate queue manager for task scheduling in backend"
This commit is contained in:
parent
6c142c04c9
commit
9d2459b056
@ -11,12 +11,11 @@ from sqlalchemy import func
|
|||||||
|
|
||||||
# Lokale Imports
|
# Lokale Imports
|
||||||
from models import init_database, create_initial_admin, User, Printer, Job, Stats, SystemLog, get_db_session, GuestRequest, UserPermission, Notification
|
from models import init_database, create_initial_admin, User, Printer, Job, Stats, SystemLog, get_db_session, GuestRequest, UserPermission, Notification
|
||||||
from utils.logging_config import setup_logging, get_logger
|
from utils.logging_config import setup_logging, get_logger, measure_execution_time, log_startup_info, debug_request, debug_response
|
||||||
from utils.decorators import measure_execution_time
|
|
||||||
from utils.file_manager import FileManager
|
from utils.file_manager import FileManager
|
||||||
from utils.job_scheduler import JobScheduler, get_job_scheduler
|
from utils.job_scheduler import JobScheduler, get_job_scheduler
|
||||||
from utils.queue_manager import start_queue_manager, stop_queue_manager, get_queue_manager
|
from utils.queue_manager import start_queue_manager, stop_queue_manager, get_queue_manager
|
||||||
from config.settings import SECRET_KEY, UPLOAD_FOLDER, ALLOWED_EXTENSIONS, ENVIRONMENT
|
from config.settings import SECRET_KEY, UPLOAD_FOLDER, ALLOWED_EXTENSIONS, ENVIRONMENT, SESSION_LIFETIME
|
||||||
|
|
||||||
# Blueprints importieren
|
# Blueprints importieren
|
||||||
from blueprints.guest import guest_blueprint
|
from blueprints.guest import guest_blueprint
|
||||||
|
@ -6,17 +6,62 @@ Queue Manager für die Verwaltung von Druckjobs in Warteschlangen.
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import List, Dict, Optional
|
from typing import List, Dict, Optional, Tuple
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
from models import get_db_session, Job, Printer, User, Notification
|
from models import get_db_session, Job, Printer, User, Notification
|
||||||
from utils.logging_config import get_logger
|
from utils.logging_config import get_logger
|
||||||
from utils.printer_status import check_printer_status
|
|
||||||
|
|
||||||
# Logger für Queue-Manager
|
# Logger für Queue-Manager
|
||||||
queue_logger = get_logger("queue_manager")
|
queue_logger = get_logger("queue_manager")
|
||||||
|
|
||||||
|
def check_printer_status(ip_address: str, timeout: int = 5) -> Tuple[str, bool]:
|
||||||
|
"""
|
||||||
|
Vereinfachte Drucker-Status-Prüfung für den Queue Manager.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ip_address: IP-Adresse der Drucker-Steckdose
|
||||||
|
timeout: Timeout in Sekunden (Standard: 5)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Tuple[str, bool]: (Status, Aktiv) - Status ist "online" oder "offline", Aktiv ist True/False
|
||||||
|
"""
|
||||||
|
if not ip_address or ip_address.strip() == "":
|
||||||
|
return "offline", False
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Ping-Test um Erreichbarkeit zu prüfen
|
||||||
|
if os.name == 'nt': # Windows
|
||||||
|
cmd = ['ping', '-n', '1', '-w', str(timeout * 1000), ip_address.strip()]
|
||||||
|
else: # Unix/Linux/macOS
|
||||||
|
cmd = ['ping', '-c', '1', '-W', str(timeout), ip_address.strip()]
|
||||||
|
|
||||||
|
result = subprocess.run(
|
||||||
|
cmd,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=timeout + 1
|
||||||
|
)
|
||||||
|
|
||||||
|
# Wenn Ping erfolgreich ist, als online betrachten
|
||||||
|
if result.returncode == 0:
|
||||||
|
queue_logger.debug(f"✅ Drucker {ip_address} ist erreichbar (Ping erfolgreich)")
|
||||||
|
return "online", True
|
||||||
|
else:
|
||||||
|
queue_logger.debug(f"❌ Drucker {ip_address} nicht erreichbar (Ping fehlgeschlagen)")
|
||||||
|
return "offline", False
|
||||||
|
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
queue_logger.warning(f"⏱️ Ping-Timeout für Drucker {ip_address} nach {timeout} Sekunden")
|
||||||
|
return "offline", False
|
||||||
|
except Exception as e:
|
||||||
|
queue_logger.error(f"❌ Fehler beim Status-Check für Drucker {ip_address}: {str(e)}")
|
||||||
|
return "offline", False
|
||||||
|
|
||||||
class PrinterQueueManager:
|
class PrinterQueueManager:
|
||||||
"""
|
"""
|
||||||
Verwaltet die Warteschlangen für offline Drucker und überwacht deren Status.
|
Verwaltet die Warteschlangen für offline Drucker und überwacht deren Status.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user