Add debugging for planned booking activation issues
This commit is contained in:
@@ -0,0 +1,177 @@
|
|||||||
|
# Fehlersuche: Geplante Ausleihen werden nicht automatisch aktiviert
|
||||||
|
|
||||||
|
## 🔍 Mögliche Ursachen
|
||||||
|
|
||||||
|
### 1. **Termin wurde für falsches Datum erstellt**
|
||||||
|
Die meisten Probleme entstehen, weil der Termin für ein **falsches Datum** (z.B. morgen statt heute) erstellt wurde.
|
||||||
|
|
||||||
|
### 2. **Scheduler läuft nicht**
|
||||||
|
Der automatische Scheduler kann deaktiviert sein oder nicht starten.
|
||||||
|
|
||||||
|
### 3. **Zeitzonen-Problem**
|
||||||
|
Die Startzeit kann in einer anderen Zeitzone gespeichert sein als erwartet.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ SOFORT-FIX: Manuell aktivieren
|
||||||
|
|
||||||
|
Falls du eine geplante Ausleihe sofort aktivieren möchtest, nutze diesen Befehl auf dem Server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec inventarsystem-mongodb mongosh --eval "
|
||||||
|
db.ausleihungen.updateOne(
|
||||||
|
{_id: ObjectId('BOOKING_ID_HIER')},
|
||||||
|
{\$set: {Status: 'active', LastUpdated: new Date()}}
|
||||||
|
)" Inventarsystem
|
||||||
|
```
|
||||||
|
|
||||||
|
Ersetze `BOOKING_ID_HIER` mit der ID deiner Ausleihe.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔧 DEBUG: Alle geplanten Ausleihen anschauen
|
||||||
|
|
||||||
|
Führe auf deinem Server aus:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec inventarsystem-mongodb mongosh --eval "
|
||||||
|
db.ausleihungen.find({Status: 'planned'}).pretty()
|
||||||
|
" Inventarsystem
|
||||||
|
```
|
||||||
|
|
||||||
|
Das zeigt dir:
|
||||||
|
- **Start**: Das gespeicherte Startdatum/Uhrzeit
|
||||||
|
- **Periode**: Die Schulstunde (falls verwendet)
|
||||||
|
- **Erstellungs-Zeit vs. aktuelle Zeit**: Vergleich
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 PROBLEM 1: Falsches Datum beim Erstellen
|
||||||
|
|
||||||
|
**Symptom**: Start-Zeit ist in der Zukunft (z.B. morgen statt heute)
|
||||||
|
|
||||||
|
**Lösung**:
|
||||||
|
1. In der Kalender-Ansicht das **richtige Datum** auswählen
|
||||||
|
2. Die **aktuelle Uhrzeit** für den Beginn nutzen (nicht eine zukünftige Zeit)
|
||||||
|
3. Für Schulstunden: Stelle sicher die **heutige Schulstunde** zu wählen
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 PROBLEM 2: Scheduler läuft nicht
|
||||||
|
|
||||||
|
**Symptom**: Keine Logs über Termin-Aktivierungen
|
||||||
|
|
||||||
|
**Überprüfung**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Container-Logs anschauen
|
||||||
|
docker logs inventarsystem-app | grep -i "scheduler\|appointment\|status update"
|
||||||
|
|
||||||
|
# 2. Scheduler ist aktiviert?
|
||||||
|
docker exec inventarsystem-app python3 -c "
|
||||||
|
import sys
|
||||||
|
sys.path.insert(0, '/app/Web')
|
||||||
|
import settings as cfg
|
||||||
|
print(f'Scheduler aktiviert: {cfg.SCHEDULER_ENABLED}')
|
||||||
|
print(f'Scheduler Intervall: {cfg.SCHEDULER_INTERVAL_MIN} Minuten')
|
||||||
|
"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Lösung wenn deaktiviert**:
|
||||||
|
- In `config.json` ändern:
|
||||||
|
```json
|
||||||
|
"scheduler": {
|
||||||
|
"enabled": true,
|
||||||
|
"interval_minutes": 1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- Container neu starten: `docker-compose restart app`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 PROBLEM 3: Startzeit als nur-Zeit (kein Datum)
|
||||||
|
|
||||||
|
**Symptom**: Start-Zeit zeigt nur "13:30" ohne Datum
|
||||||
|
|
||||||
|
**Überprüfung**: In der Datenbank nach `{Start: {$type: "string"}}` suchen statt datetime
|
||||||
|
|
||||||
|
**Lösung**: Die Ausleihe muss mit einem vollständigen Datum+Uhrzeit erstellt werden.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 AUTOMATISCHE AKTIVIERUNG TESTEN
|
||||||
|
|
||||||
|
Nach dem Fix: Erstelle eine Ausleihe für:
|
||||||
|
- **Heute** (das aktuelle Datum)
|
||||||
|
- **Schulstunde 7** (13:30-14:15)
|
||||||
|
- Startzeitpunkt sollte **jetzt oder in 1 Minute** sein
|
||||||
|
|
||||||
|
Warte 2 Minuten. Der Status sollte von `planned` zu `active` wechseln.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 SCHEDULER STATUS ÜBERPRÜFEN
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Zeige die letzten 50 Log-Zeilen
|
||||||
|
docker logs --tail 50 inventarsystem-app | tail -20
|
||||||
|
|
||||||
|
# Suche nach "Appointment status update"
|
||||||
|
docker logs inventarsystem-app 2>/dev/null | grep -i "Appointment status" | tail -5
|
||||||
|
```
|
||||||
|
|
||||||
|
Erwartete Log-Ausgabe:
|
||||||
|
```
|
||||||
|
Appointment status update finished: X changed (Y active, Z completed)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔍 DETAILLIERTE DEBUG-INFOS
|
||||||
|
|
||||||
|
Wenn obiges nicht funktioniert, führe dies aus:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec inventarsystem-app python3 -c "
|
||||||
|
from pymongo import MongoClient
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
client = MongoClient('mongodb', 27017)
|
||||||
|
db = client['Inventarsystem']
|
||||||
|
aus = db['ausleihungen']
|
||||||
|
|
||||||
|
print('=== GEPLANTE AUSLEIHEN ===')
|
||||||
|
for b in aus.find({'Status': 'planned'}).limit(3):
|
||||||
|
print(f\"Start: {b.get('Start')} | Typ: {type(b.get('Start')).__name__}\")
|
||||||
|
print(f\"Periode: {b.get('Period')} | User: {b.get('User')}\")
|
||||||
|
print(f\"Jetzt > Start? {datetime.datetime.now() > b.get('Start', datetime.datetime.max)}\")
|
||||||
|
print()
|
||||||
|
"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 💡 EMPFOHLENE EINSTELLUNG FÜR SCHULEN
|
||||||
|
|
||||||
|
In `config.json` verwende diese Werte:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"scheduler": {
|
||||||
|
"enabled": true,
|
||||||
|
"interval_minutes": 1,
|
||||||
|
"backup_interval_hours": 24
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Dies checkt **jede Minute** ob Termine aktiviert werden sollen - perfekt für Schulstunden.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Weitere Hilfe?
|
||||||
|
|
||||||
|
Falls das nicht funktioniert:
|
||||||
|
1. Schreib mir die **exakte Uhrzeit** wann du die Ausleihe erstellt hast
|
||||||
|
2. Und wann sie hätte aktiviert werden sollen
|
||||||
|
3. Zeige mir ein Beispiel aus der DB mit `docker exec inventarsystem-mongodb mongosh...`
|
||||||
@@ -85,6 +85,11 @@ def get_current_status(ausleihung, log_changes=False, user=None):
|
|||||||
new_status = 'completed'
|
new_status = 'completed'
|
||||||
# Wenn die aktuelle Zeit vor dem Startdatum liegt, ist die Ausleihung geplant
|
# Wenn die aktuelle Zeit vor dem Startdatum liegt, ist die Ausleihung geplant
|
||||||
elif current_time < start_time:
|
elif current_time < start_time:
|
||||||
|
# DEBUG: Log info wenn Booking noch lange in der Zukunft ist
|
||||||
|
time_until_start = (start_time - current_time).total_seconds()
|
||||||
|
if time_until_start > 3600: # Mehr als 1 Stunde entfernt
|
||||||
|
ausleihung_id = str(ausleihung.get('_id', 'unknown'))[:12]
|
||||||
|
print(f"[DEBUG] Ausleihe {ausleihung_id} startet in {time_until_start/3600:.1f} Stunden ({start_time}), noch geplant")
|
||||||
new_status = 'planned'
|
new_status = 'planned'
|
||||||
# Wenn kein Enddatum gesetzt ist oder die aktuelle Zeit vor dem Enddatum liegt,
|
# Wenn kein Enddatum gesetzt ist oder die aktuelle Zeit vor dem Enddatum liegt,
|
||||||
# ist die Ausleihung aktiv
|
# ist die Ausleihung aktiv
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Debug script to check why planned bookings are not being activated
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'Web'))
|
||||||
|
|
||||||
|
from pymongo import MongoClient
|
||||||
|
import settings as cfg
|
||||||
|
import ausleihung as au
|
||||||
|
|
||||||
|
def check_bookings():
|
||||||
|
"""Check all planned bookings and their status"""
|
||||||
|
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||||
|
db = client[cfg.MONGODB_DB]
|
||||||
|
ausleihungen = db['ausleihungen']
|
||||||
|
|
||||||
|
# Get all planned bookings
|
||||||
|
planned = list(ausleihungen.find({'Status': 'planned'}))
|
||||||
|
|
||||||
|
print(f"\n📊 Gefundene GEPLANTE Ausleihen: {len(planned)}\n")
|
||||||
|
print("=" * 100)
|
||||||
|
|
||||||
|
current_time = datetime.datetime.now()
|
||||||
|
print(f"⏰ Aktuelle Zeit: {current_time}\n")
|
||||||
|
|
||||||
|
for booking in planned:
|
||||||
|
booking_id = str(booking['_id'])
|
||||||
|
user = booking.get('User', 'N/A')
|
||||||
|
item = booking.get('Item', 'N/A')
|
||||||
|
start = booking.get('Start')
|
||||||
|
end = booking.get('End')
|
||||||
|
period = booking.get('Period')
|
||||||
|
status = booking.get('Status')
|
||||||
|
|
||||||
|
print(f"\n🔹 Ausleihe ID: {booking_id}")
|
||||||
|
print(f" Benutzer: {user}")
|
||||||
|
print(f" Item: {item}")
|
||||||
|
print(f" Status: {status}")
|
||||||
|
print(f" Schulstunde/Periode: {period}")
|
||||||
|
print(f" Start: {start} (Typ: {type(start).__name__})")
|
||||||
|
print(f" Ende: {end} (Typ: {type(end).__name__})")
|
||||||
|
|
||||||
|
# Check current status
|
||||||
|
current_status = au.get_current_status(booking, log_changes=False)
|
||||||
|
print(f" ✓ Berechneter Status: {current_status}")
|
||||||
|
|
||||||
|
if current_status != status:
|
||||||
|
print(f" ⚠️ STATUS STIMMT NICHT ÜBEREIN! Sollte sein: {current_status}")
|
||||||
|
|
||||||
|
# Check time comparison
|
||||||
|
if start:
|
||||||
|
time_diff = (current_time - start).total_seconds()
|
||||||
|
if time_diff < 0:
|
||||||
|
print(f" ⏳ Startet in: {abs(time_diff) / 60:.1f} Minuten")
|
||||||
|
elif time_diff < 3600:
|
||||||
|
print(f" ✓ Sollte JETZT AKTIV sein! ({time_diff / 60:.1f} Minuten vorbei)")
|
||||||
|
else:
|
||||||
|
print(f" ✓ Sollte schon {time_diff / 3600:.1f} Stunden aktiv sein!")
|
||||||
|
|
||||||
|
print("\n" + "=" * 100)
|
||||||
|
|
||||||
|
# Check active bookings too
|
||||||
|
active = list(ausleihungen.find({'Status': 'active'}))
|
||||||
|
print(f"\n✓ AKTIVE Ausleihen: {len(active)}")
|
||||||
|
for booking in active:
|
||||||
|
print(f" - {booking.get('User', 'N/A')}: {booking.get('Item', 'N/A')} (Periode: {booking.get('Period')})")
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
check_bookings()
|
||||||
Reference in New Issue
Block a user