From c29fde0cb0313d9e32fb29547bd487e8072da71d Mon Sep 17 00:00:00 2001 From: tanshu Date: Fri, 19 Mar 2021 08:06:37 +0530 Subject: [PATCH] Printer Cut Code should be properly handled now in editing as well. Worker will retry a failed job. The worker was using the wrong queue name. --- barker/alembic/versions/34fe3d061c5f_finish_import.py | 2 +- barker/barker/routers/printer.py | 4 ++-- barker/barker/tasks/printing.py | 6 ++++++ barker/barker/worker.py | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/barker/alembic/versions/34fe3d061c5f_finish_import.py b/barker/alembic/versions/34fe3d061c5f_finish_import.py index 1f413a9..5840f6c 100644 --- a/barker/alembic/versions/34fe3d061c5f_finish_import.py +++ b/barker/alembic/versions/34fe3d061c5f_finish_import.py @@ -72,7 +72,7 @@ def update_section_printers(): values={"printer_id": select([printer.c.id]).where(section_printer.c.printer_name == printer.c.name)} ) ) - op.execute(printer.update(values={"cut_code": "\x1dV\x41\x03"})) + op.execute(printer.update(values={"cut_code": "\x1d\x56\x41\x03"})) with op.batch_alter_table("section_printers") as batch_op: batch_op.alter_column("section_id", nullable=False) batch_op.drop_column("section_name") diff --git a/barker/barker/routers/printer.py b/barker/barker/routers/printer.py index 5054624..e17ad55 100644 --- a/barker/barker/routers/printer.py +++ b/barker/barker/routers/printer.py @@ -33,7 +33,7 @@ def save( user: UserToken = Security(get_user, scopes=["printers"]), ) -> schemas.Printer: try: - item = Printer(name=data.name, address=data.address, cut_code=data.cut_code) + item = Printer(name=data.name, address=data.address, cut_code=bytearray.fromhex(data.cut_code).decode()) db.add(item) db.commit() return printer_info(item) @@ -59,7 +59,7 @@ def update( item: Printer = db.query(Printer).filter(Printer.id == id_).first() item.name = data.name item.address = data.address - item.cut_code = data.cut_code + item.cut_code = bytearray.fromhex(data.cut_code).decode() db.commit() return printer_info(item) except SQLAlchemyError as e: diff --git a/barker/barker/tasks/printing.py b/barker/barker/tasks/printing.py index 96e7380..9f73004 100644 --- a/barker/barker/tasks/printing.py +++ b/barker/barker/tasks/printing.py @@ -2,6 +2,8 @@ import re # noqa: F401 import socket # noqa: F401 import sys # noqa: F401 +from arq import Retry + async def sent_to_printer(ctx: dict, data: str, address: str, cut_code: str): print(ctx, data, address, cut_code) @@ -15,6 +17,10 @@ async def sent_to_printer(ctx: dict, data: str, address: str, cut_code: str): print("Lookup error:", e) except: # noqa: E722 print("Unexpected error:", sys.exc_info()[0]) + # retry the job with increasing back-off + # delays will be 5s, 10s, 15s, 20s + # after max_tries (default 5) the job will permanently fail + raise Retry(defer=ctx["job_try"] * 5) # GS = "\x1d" # PAPER_CUT = GS + "V" diff --git a/barker/barker/worker.py b/barker/barker/worker.py index fbcfdef..076964a 100644 --- a/barker/barker/worker.py +++ b/barker/barker/worker.py @@ -25,7 +25,7 @@ class WorkerSettings: Settings for the ARQ worker. """ - queue_name = f"barker:printer:{sett.WORKER_QUEUE_NAME}" + queue_name = f"barker:print:{sett.WORKER_QUEUE_NAME}" redis_settings = settings functions: list = [sent_to_printer] on_startup = startup