🐛 Refactor: Update printer status handling and session management. Improved caching mechanism for live printer status and added summary functionality. Removed obsolete database files for better organization.
This commit is contained in:
@@ -9,7 +9,6 @@ from flask_login import login_required, current_user
|
||||
from datetime import datetime, timedelta
|
||||
from models import User, get_db_session, SystemLog
|
||||
from utils.logging_config import get_logger
|
||||
from utils.utilities_collection import SESSION_LIFETIME
|
||||
|
||||
# Blueprint erstellen
|
||||
sessions_blueprint = Blueprint('sessions', __name__, url_prefix='/api/session')
|
||||
@@ -17,6 +16,20 @@ sessions_blueprint = Blueprint('sessions', __name__, url_prefix='/api/session')
|
||||
# Logger initialisieren
|
||||
sessions_logger = get_logger("sessions")
|
||||
|
||||
# Session-Lifetime sicher importieren
|
||||
try:
|
||||
from utils.utilities_collection import SESSION_LIFETIME
|
||||
# Sicherstellen, dass es ein timedelta ist
|
||||
if isinstance(SESSION_LIFETIME, (int, float)):
|
||||
SESSION_LIFETIME_TD = timedelta(seconds=SESSION_LIFETIME)
|
||||
elif isinstance(SESSION_LIFETIME, timedelta):
|
||||
SESSION_LIFETIME_TD = SESSION_LIFETIME
|
||||
else:
|
||||
SESSION_LIFETIME_TD = timedelta(hours=1) # Fallback: 1 Stunde
|
||||
except ImportError:
|
||||
SESSION_LIFETIME_TD = timedelta(hours=1) # Fallback: 1 Stunde
|
||||
sessions_logger.warning("SESSION_LIFETIME konnte nicht importiert werden, verwende Fallback (1h)")
|
||||
|
||||
@sessions_blueprint.route('/heartbeat', methods=['POST'])
|
||||
@login_required
|
||||
def heartbeat():
|
||||
@@ -40,14 +53,14 @@ def heartbeat():
|
||||
session_start = session.get('session_start')
|
||||
if session_start:
|
||||
elapsed = (datetime.now() - datetime.fromisoformat(session_start)).total_seconds()
|
||||
remaining = max(0, SESSION_LIFETIME.total_seconds() - elapsed)
|
||||
remaining = max(0, SESSION_LIFETIME_TD.total_seconds() - elapsed)
|
||||
else:
|
||||
remaining = SESSION_LIFETIME.total_seconds()
|
||||
remaining = SESSION_LIFETIME_TD.total_seconds()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'remaining_seconds': int(remaining),
|
||||
'session_lifetime': int(SESSION_LIFETIME.total_seconds())
|
||||
'session_lifetime': int(SESSION_LIFETIME_TD.total_seconds())
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
@@ -66,9 +79,9 @@ def status():
|
||||
# Verbleibende Zeit berechnen
|
||||
if session_start:
|
||||
elapsed = (datetime.now() - datetime.fromisoformat(session_start)).total_seconds()
|
||||
remaining = max(0, SESSION_LIFETIME.total_seconds() - elapsed)
|
||||
remaining = max(0, SESSION_LIFETIME_TD.total_seconds() - elapsed)
|
||||
else:
|
||||
remaining = SESSION_LIFETIME.total_seconds()
|
||||
remaining = SESSION_LIFETIME_TD.total_seconds()
|
||||
|
||||
# Inaktivitätszeit berechnen
|
||||
if last_activity:
|
||||
@@ -90,7 +103,7 @@ def status():
|
||||
'last_activity': last_activity,
|
||||
'remaining_seconds': int(remaining),
|
||||
'inactive_seconds': int(inactive_seconds),
|
||||
'lifetime_seconds': int(SESSION_LIFETIME.total_seconds()),
|
||||
'lifetime_seconds': int(SESSION_LIFETIME_TD.total_seconds()),
|
||||
'is_permanent': session.permanent
|
||||
}
|
||||
})
|
||||
@@ -128,7 +141,7 @@ def extend():
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'message': 'Session wurde verlängert',
|
||||
'new_lifetime_seconds': int(SESSION_LIFETIME.total_seconds())
|
||||
'new_lifetime_seconds': int(SESSION_LIFETIME_TD.total_seconds())
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
|
Reference in New Issue
Block a user