feat: update logger logic
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
from __future__ import annotations
|
||||
from decimal import Decimal
|
||||
from ulid import ULID
|
||||
from src.application.abstractions import IUnitOfWork
|
||||
from src.application.contracts import IReceipt
|
||||
from src.application.contracts import ILogger,IReceipt
|
||||
from src.application.domain.exceptions import ApplicationException
|
||||
from src.infrastructure.database.decorators import transactional
|
||||
|
||||
|
||||
class CreateCryptoTransferCompletedCommand:
|
||||
def __init__(self, *, unit_of_work: IUnitOfWork, receipt: IReceipt):
|
||||
def __init__(self, *, unit_of_work: IUnitOfWork, receipt: IReceipt, logger: ILogger):
|
||||
self._unit_of_work = unit_of_work
|
||||
self._receipt = receipt
|
||||
self._logger = logger
|
||||
|
||||
|
||||
@transactional
|
||||
@@ -72,7 +72,7 @@ class CreateCryptoTransferCompletedCommand:
|
||||
customer_info=customer_info,
|
||||
customer_inn=customer_inn,
|
||||
customer_birthday=customer_birthday,
|
||||
request_id=str(ULID()),
|
||||
request_id=self._logger.get_trace_id(),
|
||||
)
|
||||
receipt_model = receipt_response.get('Model')
|
||||
if not isinstance(receipt_model, dict):
|
||||
|
||||
@@ -66,7 +66,7 @@ class CreateOrderCommand:
|
||||
)
|
||||
|
||||
saved = await self._unit_of_work.order_repository.create(order)
|
||||
with_itpay = await self._itpay_service.create_payment(saved)
|
||||
with_itpay = await self._itpay_service.create_payment(saved,self._logger.get_trace_id())
|
||||
if with_itpay.status in (
|
||||
OrderStatus.CANCELLED,
|
||||
OrderStatus.REJECTED,
|
||||
|
||||
@@ -21,6 +21,8 @@ class CreatePaymentCommand:
|
||||
metadata = payment.metadata or {}
|
||||
order_id = str(metadata.get('order_id') or '')
|
||||
user_id = str(metadata.get('user_id') or '')
|
||||
trace_id = str(metadata.get('trace_id') or self._logger.get_trace_id())
|
||||
self._logger.set_trace_id(trace_id)
|
||||
if not order_id:
|
||||
raise ApplicationException(status_code=400, message='Itpay webhook metadata missing order_id')
|
||||
if not user_id:
|
||||
@@ -40,7 +42,7 @@ class CreatePaymentCommand:
|
||||
message: dict[str,str] = {
|
||||
'order_id': order_id,
|
||||
'user_id': user_id,
|
||||
'trace_id': self._logger.get_trace_id(),
|
||||
'trace_id': trace_id,
|
||||
'message_id': message_id,
|
||||
}
|
||||
await self._queue_messanger.publish_to_queue(
|
||||
@@ -48,4 +50,5 @@ class CreatePaymentCommand:
|
||||
message=message,
|
||||
message_id=message_id,
|
||||
correlation_id=message['trace_id'],
|
||||
headers={'trace_id': trace_id},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user