fix: Update async handling in send_shop_order_invoice_telegram_task for Celery compatibility

This commit is contained in:
Parsa Nazer
2025-12-28 12:18:15 +03:30
parent 189fdbbb1b
commit 6c7744935d
+7 -2
View File
@@ -161,8 +161,13 @@ def send_shop_order_invoice_telegram_task(shop_order_id, chat_id, bot_token):
caption=f'فاکتور سفارش #{shop_order_id}\n{shop_order.shop.shop_name}'
)
# Run async function
asyncio.run(send_invoice())
# Run async function - create new event loop for Celery context
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(send_invoice())
finally:
loop.close()
logging.info(f'Successfully sent shop order invoice {shop_order_id} to Telegram chat {chat_id}')
return f'Invoice sent successfully to chat {chat_id}'