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.
This commit is contained in:
Amritanshu Agrawal 2021-03-19 08:06:37 +05:30
parent dc6e7fe467
commit c29fde0cb0
4 changed files with 10 additions and 4 deletions

View File

@ -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")

View File

@ -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:

View File

@ -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"

View File

@ -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