asdfasd
This commit is contained in:
parent
d06716ac92
commit
00d737714b
31
app.py
31
app.py
@ -11,7 +11,6 @@ import mimetypes
|
|||||||
import logging
|
import logging
|
||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
import time
|
import time
|
||||||
import fcntl # For file locking
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -85,24 +84,15 @@ def print_address_label(pdf_path):
|
|||||||
cut=True
|
cut=True
|
||||||
)
|
)
|
||||||
|
|
||||||
app.logger.info("Attempting to acquire printer lock...")
|
app.logger.info("Sending to printer...")
|
||||||
|
send(
|
||||||
# Open the printer device and lock it to prevent concurrent access
|
instructions=instructions,
|
||||||
with open(printer, 'wb') as printer_device:
|
printer_identifier=printer,
|
||||||
fcntl.flock(printer_device, fcntl.LOCK_EX) # Exclusive lock on printer device
|
backend_identifier=backend,
|
||||||
try:
|
blocking=True
|
||||||
app.logger.info("Sending to printer...")
|
)
|
||||||
send(
|
app.logger.info("Print job sent successfully")
|
||||||
instructions=instructions,
|
|
||||||
printer_identifier=printer,
|
|
||||||
backend_identifier=backend,
|
|
||||||
blocking=True
|
|
||||||
)
|
|
||||||
app.logger.info("Print job sent successfully")
|
|
||||||
finally:
|
|
||||||
# Ensure the lock is released after the print job is finished
|
|
||||||
fcntl.flock(printer_device, fcntl.LOCK_UN)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
app.logger.error(f"Error during printing: {str(e)}")
|
app.logger.error(f"Error during printing: {str(e)}")
|
||||||
|
|
||||||
@ -116,7 +106,6 @@ def process_queue():
|
|||||||
# Process the file (convert and print)
|
# Process the file (convert and print)
|
||||||
app.logger.info(f"Processing file: {file_path}")
|
app.logger.info(f"Processing file: {file_path}")
|
||||||
print_address_label(file_path)
|
print_address_label(file_path)
|
||||||
time.sleep(10)
|
|
||||||
# Signal that the task is done
|
# Signal that the task is done
|
||||||
file_queue.task_done()
|
file_queue.task_done()
|
||||||
|
|
||||||
@ -154,4 +143,4 @@ def upload_file():
|
|||||||
return jsonify({'message': f'File {file.filename} uploaded and queued for processing'}), 200
|
return jsonify({'message': f'File {file.filename} uploaded and queued for processing'}), 200
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
Loading…
x
Reference in New Issue
Block a user