f
This commit is contained in:
parent
c53baccb38
commit
2561febca9
46
app.py
46
app.py
@ -10,6 +10,7 @@ from PIL import Image
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
|
import time
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -79,20 +80,37 @@ def print_address_label(pdf_path):
|
|||||||
cut=True
|
cut=True
|
||||||
)
|
)
|
||||||
|
|
||||||
app.logger.info("Waiting to acquire printer lock...")
|
# Try to acquire the printer lock with a timeout
|
||||||
with printer_lock: # Ensure only one thread sends a job at a time
|
max_retries = 3
|
||||||
app.logger.info("Sending to printer...")
|
retry_delay = 2 # seconds
|
||||||
try:
|
for attempt in range(max_retries):
|
||||||
send(
|
if printer_lock.acquire(timeout=5): # 5 seconds timeout
|
||||||
instructions=instructions,
|
try:
|
||||||
printer_identifier=printer,
|
app.logger.info(f"Attempting to send print job (Attempt {attempt + 1})...")
|
||||||
backend_identifier=backend,
|
send(
|
||||||
blocking=True
|
instructions=instructions,
|
||||||
)
|
printer_identifier=printer,
|
||||||
app.logger.info("Print job sent successfully")
|
backend_identifier=backend,
|
||||||
except Exception as e:
|
blocking=True
|
||||||
app.logger.error(f"Error during printing: {str(e)}")
|
)
|
||||||
|
app.logger.info("Print job sent successfully")
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f"Error during printing: {str(e)}")
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
app.logger.info(f"Retrying after {retry_delay} seconds...")
|
||||||
|
time.sleep(retry_delay)
|
||||||
|
else:
|
||||||
|
app.logger.error("Max retries reached. Failed to send print job.")
|
||||||
|
else:
|
||||||
|
app.logger.error(f"Failed to acquire printer lock (Attempt {attempt + 1}). Printer is busy.")
|
||||||
|
if attempt < max_retries - 1:
|
||||||
|
app.logger.info(f"Retrying after {retry_delay} seconds...")
|
||||||
|
time.sleep(retry_delay)
|
||||||
|
else:
|
||||||
|
app.logger.error("Printer is still busy after retries.")
|
||||||
|
raise Exception("Printer is busy. Try again later.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"Error during label printing: {str(e)}")
|
app.logger.error(f"Error during label printing: {str(e)}")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user