Fix: Suddenly got errors saying that the redis.enqueue job was running in a different loop

This commit is contained in:
Amritanshu Agrawal 2022-06-21 12:39:51 +05:30
parent a4db3b24f0
commit 236c746e1c
6 changed files with 24 additions and 12 deletions

View File

@ -62,12 +62,14 @@ def print_bill(voucher_id: uuid.UUID, db: Session):
for i in [it for it in items_dict.values() if it.quantity != 0]:
get_tax_item(i.tax.id, i.tax.name, i.tax_amount, tax)
data = design_bill(voucher, list(items_dict.values()), list(tax.values()), db)
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
asyncio.run(
loop = asyncio.new_event_loop()
redis: ArqRedis = loop.run_until_complete(create_pool(redis_settings))
loop.run_until_complete(
redis.enqueue_job(
"sent_to_printer", data, printer.address, printer.cut_code, _queue_name=f"barker:print:{printer.name}"
)
)
loop.close()
def get_tax_item(

View File

@ -28,12 +28,14 @@ def print_cashier_report(report: CashierReport, device_id: uuid.UUID, db: Sessio
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
asyncio.run(
loop = asyncio.new_event_loop()
redis: ArqRedis = loop.run_until_complete(create_pool(redis_settings))
loop.run_until_complete(
redis.enqueue_job(
"sent_to_printer", data, printer.address, printer.cut_code, _queue_name=f"barker:print:{printer.name}"
)
)
loop.close()
def design_cashier_report(report: CashierReport):

View File

@ -25,12 +25,14 @@ def print_discount_report(report: DiscountReport, device_id: uuid.UUID, db: Sess
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
asyncio.run(
loop = asyncio.new_event_loop()
redis: ArqRedis = loop.run_until_complete(create_pool(redis_settings))
loop.run_until_complete(
redis.enqueue_job(
"sent_to_printer", data, printer.address, printer.cut_code, _queue_name=f"barker:print:{printer.name}"
)
)
loop.close()
def design_discount_report(report: DiscountReport):

View File

@ -104,13 +104,14 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
if key not in my_hash:
my_hash[key] = (printer, [])
my_hash[key][1].append(item)
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
loop = asyncio.new_event_loop()
redis: ArqRedis = loop.run_until_complete(create_pool(redis_settings))
for key, value in my_hash.items():
printer_id, copies = key
printer, items = value
for c in range(int(copies)):
data = design_kot(voucher, kot, items, c, db)
asyncio.run(
loop.run_until_complete(
redis.enqueue_job(
"sent_to_printer",
data,
@ -119,3 +120,4 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
_queue_name=f"barker:print:{printer.name}",
)
)
loop.close()

View File

@ -26,12 +26,14 @@ def print_product_sale_report(report, device_id: uuid.UUID, db: Session):
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
asyncio.run(
loop = asyncio.new_event_loop()
redis: ArqRedis = loop.run_until_complete(create_pool(redis_settings))
loop.run_until_complete(
redis.enqueue_job(
"sent_to_printer", data, printer.address, printer.cut_code, _queue_name=f"barker:print:{printer.name}"
)
)
loop.close()
def design_product_sale_report(report):

View File

@ -28,12 +28,14 @@ def print_sale_report(report: SaleReport, device_id: uuid.UUID, db: Session):
.where(SectionPrinter.sale_category_id == None) # noqa: E711
).scalar_one()
redis: ArqRedis = asyncio.run(create_pool(redis_settings))
asyncio.run(
loop = asyncio.new_event_loop()
redis: ArqRedis = loop.run_until_complete(create_pool(redis_settings))
loop.run_until_complete(
redis.enqueue_job(
"sent_to_printer", data, printer.address, printer.cut_code, _queue_name=f"barker:print:{printer.name}"
)
)
loop.close()
def design_sale_report(report: SaleReport):