Automatisches Ausschalten der Steckdosen nach Jobende implementiert
- Neue API zur Statusüberprüfung für Frontend hinzugefügt - Automatisches Ausschalten der Steckdosen bei Jobende implementiert - Zurücksetzen des Steckdosenstatus nach Jobende verbessert - check-jobs CLI-Befehl optimiert 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8222d89b2b
commit
47143d29a5
@ -838,7 +838,28 @@ def job_remaining_time(job_id):
|
|||||||
return jsonify({'message': 'Job nicht gefunden!'}), 404
|
return jsonify({'message': 'Job nicht gefunden!'}), 404
|
||||||
|
|
||||||
remaining = calculate_remaining_time(job)
|
remaining = calculate_remaining_time(job)
|
||||||
return jsonify({'remaining_minutes': remaining})
|
|
||||||
|
# Wenn die verbleibende Zeit 0 ist und der Job nicht manuell abgebrochen wurde,
|
||||||
|
# automatisch die Steckdose ausschalten und Status aktualisieren
|
||||||
|
if remaining == 0 and not job['aborted']:
|
||||||
|
socket = get_socket_by_id(job['socket_id'])
|
||||||
|
if socket and socket['status'] == 1: # busy
|
||||||
|
update_socket(socket['id'], status=0) # available
|
||||||
|
app.logger.info(f"Job {job['id']} abgelaufen. Steckdose {socket['id']} auf verfügbar gesetzt.")
|
||||||
|
|
||||||
|
# Steckdose ausschalten, falls IP-Adresse hinterlegt ist
|
||||||
|
if socket['ip_address']:
|
||||||
|
try:
|
||||||
|
turn_off_socket(socket['ip_address'])
|
||||||
|
app.logger.info(f"Steckdose {socket['ip_address']} für abgelaufenen Job {job['id']} automatisch ausgeschaltet.")
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f"Fehler beim Ausschalten der Steckdose {socket['ip_address']}: {e}")
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'remaining_minutes': remaining,
|
||||||
|
'job_status': 'completed' if remaining == 0 else 'active',
|
||||||
|
'socket_status': 'available' if remaining == 0 else 'busy'
|
||||||
|
})
|
||||||
|
|
||||||
@app.route('/api/users', methods=['GET'])
|
@app.route('/api/users', methods=['GET'])
|
||||||
@login_required
|
@login_required
|
||||||
@ -954,16 +975,52 @@ def check_jobs():
|
|||||||
update_socket(socket['id'], status=0) # available
|
update_socket(socket['id'], status=0) # available
|
||||||
app.logger.info(f"Job {job['id']} abgelaufen. Steckdose {socket['id']} auf verfügbar gesetzt.")
|
app.logger.info(f"Job {job['id']} abgelaufen. Steckdose {socket['id']} auf verfügbar gesetzt.")
|
||||||
|
|
||||||
# Steckdose ausschalten, falls IP-Adresse hinterlegt ist
|
# Steckdose ausschalten, falls IP-Adresse hinterlegt ist
|
||||||
if socket and socket['ip_address']:
|
if socket['ip_address']:
|
||||||
try:
|
try:
|
||||||
turn_off_socket(socket['ip_address'])
|
turn_off_socket(socket['ip_address'])
|
||||||
app.logger.info(f"Steckdose {socket['ip_address']} für abgelaufenen Job {job['id']} ausgeschaltet.")
|
app.logger.info(f"Steckdose {socket['ip_address']} für abgelaufenen Job {job['id']} ausgeschaltet.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"Fehler beim Ausschalten der Steckdose {socket['ip_address']}: {e}")
|
app.logger.error(f"Fehler beim Ausschalten der Steckdose {socket['ip_address']}: {e}")
|
||||||
|
|
||||||
app.logger.info(f"{len(expired_jobs)} abgelaufene Jobs überprüft und Steckdosen aktualisiert.")
|
app.logger.info(f"{len(expired_jobs)} abgelaufene Jobs überprüft und Steckdosen aktualisiert.")
|
||||||
|
|
||||||
|
@app.route('/api/job/<job_id>/status', methods=['GET'])
|
||||||
|
def job_status(job_id):
|
||||||
|
"""Endpunkt zum Überprüfen des Status eines Jobs für Frontend-Polling."""
|
||||||
|
job = get_job_by_id(job_id)
|
||||||
|
if not job:
|
||||||
|
return jsonify({'message': 'Job nicht gefunden!'}), 404
|
||||||
|
|
||||||
|
remaining = calculate_remaining_time(job)
|
||||||
|
socket = get_socket_by_id(job['socket_id'])
|
||||||
|
socket_status = socket['status'] if socket else None
|
||||||
|
|
||||||
|
# Wenn die verbleibende Zeit 0 ist und der Job nicht manuell abgebrochen wurde,
|
||||||
|
# automatisch die Steckdose ausschalten und Status aktualisieren
|
||||||
|
if remaining == 0 and not job['aborted'] and socket and socket['status'] == 1:
|
||||||
|
# Update socket status to available
|
||||||
|
update_socket(socket['id'], status=0)
|
||||||
|
socket_status = 0
|
||||||
|
app.logger.info(f"Job {job['id']} abgelaufen. Steckdose {socket['id']} auf verfügbar gesetzt.")
|
||||||
|
|
||||||
|
# Steckdose ausschalten, falls IP-Adresse hinterlegt ist
|
||||||
|
if socket['ip_address']:
|
||||||
|
try:
|
||||||
|
turn_off_socket(socket['ip_address'])
|
||||||
|
app.logger.info(f"Steckdose {socket['ip_address']} für abgelaufenen Job {job['id']} automatisch ausgeschaltet.")
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f"Fehler beim Ausschalten der Steckdose {socket['ip_address']}: {e}")
|
||||||
|
|
||||||
|
job_status = 'aborted' if job['aborted'] else ('completed' if remaining == 0 else 'active')
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'job': job_to_dict(job),
|
||||||
|
'status': job_status,
|
||||||
|
'socketStatus': 'available' if socket_status == 0 else 'busy',
|
||||||
|
'remainingMinutes': remaining
|
||||||
|
})
|
||||||
|
|
||||||
@app.route('/api/test', methods=['GET'])
|
@app.route('/api/test', methods=['GET'])
|
||||||
def test():
|
def test():
|
||||||
return jsonify({'message': 'MYP Backend API funktioniert!'})
|
return jsonify({'message': 'MYP Backend API funktioniert!'})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user