|
@@ -128,9 +128,9 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
|
|
|
# '-c 1' para Linux/Mac, '-W 2' timeout de 2 segundos para evitar bloqueos largos
|
|
# '-c 1' para Linux/Mac, '-W 2' timeout de 2 segundos para evitar bloqueos largos
|
|
|
# stdout=subprocess.DEVNULL silencia la salida en consola
|
|
# stdout=subprocess.DEVNULL silencia la salida en consola
|
|
|
response = subprocess.run(
|
|
response = subprocess.run(
|
|
|
- ["ping", "-c", "1", "-W", "2", ip],
|
|
|
|
|
|
|
+ ["/usr/bin/ping", "-c", "1", "-W", "2", ip],
|
|
|
stdout=subprocess.DEVNULL,
|
|
stdout=subprocess.DEVNULL,
|
|
|
- stderr=subprocess.DEVNULL
|
|
|
|
|
|
|
+ stderr=subprocess.DEVNULL,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
if response.returncode != 0:
|
|
if response.returncode != 0:
|
|
@@ -141,33 +141,32 @@ async def printer_order(order: OrderWeb, current_user: User = Depends(get_curren
|
|
|
failed_printers.append(name)
|
|
failed_printers.append(name)
|
|
|
print(failed_printers)
|
|
print(failed_printers)
|
|
|
# Procesamiento de errores
|
|
# Procesamiento de errores
|
|
|
- if not DEVELOPMENT:
|
|
|
|
|
- if failed_printers:
|
|
|
|
|
- logger.error(f"Printer is not connected: {failed_printers}. Order from user {current_user.email} cannot be processed.")
|
|
|
|
|
|
|
+ if failed_printers:
|
|
|
|
|
+ logger.error(f"Printer is not connected: {failed_printers}. Order from user {current_user.email} cannot be processed.")
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ locations_str = ", ".join(failed_printers)
|
|
|
|
|
|
|
|
- try:
|
|
|
|
|
- locations_str = ", ".join(failed_printers)
|
|
|
|
|
-
|
|
|
|
|
- email_thread = Thread(
|
|
|
|
|
- target=get_email_sender().send_email,
|
|
|
|
|
- args=(
|
|
|
|
|
- PRINTER_DISCONNECTED_MAIL["subject"].format(location=locations_str),
|
|
|
|
|
- PRINTER_DISCONNECTED_MAIL["body"].format(
|
|
|
|
|
- location=locations_str,
|
|
|
|
|
- timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
- ),
|
|
|
|
|
- ["erwinjacimino2003@gmail.com", "mompyn@gmail.com"]
|
|
|
|
|
|
|
+ email_thread = Thread(
|
|
|
|
|
+ target=get_email_sender().send_email,
|
|
|
|
|
+ args=(
|
|
|
|
|
+ PRINTER_DISCONNECTED_MAIL["subject"].format(location=locations_str),
|
|
|
|
|
+ PRINTER_DISCONNECTED_MAIL["body"].format(
|
|
|
|
|
+ location=locations_str,
|
|
|
|
|
+ timestamp=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
),
|
|
),
|
|
|
- daemon=True
|
|
|
|
|
- )
|
|
|
|
|
- email_thread.start()
|
|
|
|
|
-
|
|
|
|
|
- return error_response(message=ErrorResponse.PRINTER_DISCONNECTED, status_code=424)
|
|
|
|
|
-
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- logger.error(f"Error sending notification: {e}")
|
|
|
|
|
- # Retornamos el error original de impresora, no el del email
|
|
|
|
|
- return error_response(message=ErrorResponse.PRINTER_DISCONNECTED, status_code=424)
|
|
|
|
|
|
|
+ ["erwinjacimino2003@gmail.com", "mompyn@gmail.com"]
|
|
|
|
|
+ ),
|
|
|
|
|
+ daemon=True
|
|
|
|
|
+ )
|
|
|
|
|
+ email_thread.start()
|
|
|
|
|
+
|
|
|
|
|
+ return error_response(message=ErrorResponse.PRINTER_DISCONNECTED, status_code=424)
|
|
|
|
|
+
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(f"Error sending notification: {e}")
|
|
|
|
|
+ # Retornamos el error original de impresora, no el del email
|
|
|
|
|
+ return error_response(message=ErrorResponse.PRINTER_DISCONNECTED, status_code=424)
|
|
|
|
|
|
|
|
|
|
|
|
|
# Input validation
|
|
# Input validation
|