Skip to content

Commit

Permalink
refactor: message strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Noyan Aziz authored and Muhammad Noyan Aziz committed Nov 7, 2024
1 parent 614a5b3 commit d0a87e1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
21 changes: 10 additions & 11 deletions commerce_coordinator/apps/commercetools/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def get_orders(self, customer: CTCustomer, offset=0,

start_time = datetime.datetime.now()
logger.info(
"[UserOrdersView] [CommercetoolsAPIClient] - Get orders query call started at %s", start_time)
"[UserOrdersView] Get CT orders query call started at %s", start_time)
values = self.base_client.orders.query(
where=["customerId=:cid", order_where_clause],
predicate_var={'cid': customer.id},
Expand All @@ -272,18 +272,18 @@ def get_orders(self, customer: CTCustomer, offset=0,
)
end_time = datetime.datetime.now()
logger.info(
"[UserOrdersView] [CommercetoolsAPIClient] - Get orders query call finished at %s with total duration: %s",
"[UserOrdersView] Get CT orders query call finished at %s with total duration: %s",
end_time, end_time - start_time
)

start_time = datetime.datetime.now()
logger.info('[UserOrdersView] [CommercetoolsAPIClient] - Pagination of CT orders started at %s',
logger.info('[UserOrdersView] Pagination of CT orders started at %s',
start_time)
result = PaginatedResult(values.results, values.total, values.offset)
end_time = datetime.datetime.now()
logger.info(
'[UserOrdersView] [CommercetoolsAPIClient] - \
Pagination of CT orders finished at %s with total duration: %s', end_time, end_time - start_time)
'[UserOrdersView] Pagination of CT orders finished at %s with total duration: %s',
end_time, end_time - start_time)

return result

Expand All @@ -298,27 +298,26 @@ def get_orders_for_customer(self, edx_lms_user_id: int, offset=0,
"""
start_time = datetime.datetime.now()
logger.info(
"[UserOrdersView] [CommercetoolsAPIClient] - Getting customer if from lms id call started at %s",
"[UserOrdersView] For CT orders get customer id from lms id call started at %s",
start_time
)
customer = self.get_customer_by_lms_user_id(edx_lms_user_id)
end_time = datetime.datetime.now()
logger.info(
"[UserOrdersView] [CommercetoolsAPIClient] - \
Getting customer if from lms id call finished at %s with total duration: %s",
"[UserOrdersView] For CT orders get customer id from lms id call finished at %s with total duration: %s",
end_time, end_time - start_time
)

if customer is None: # pragma: no cover
raise ValueError(f'Unable to locate customer with ID #{edx_lms_user_id}')

start_time = datetime.datetime.now()
logger.info("[UserOrdersView] [CommercetoolsAPIClient] - Get orders call started at %s",
logger.info("[UserOrdersView] Get CT orders call started at %s",
start_time)
orders = self.get_orders(customer, offset, limit)
end_time = datetime.datetime.now()
logger.info("[UserOrdersView] [CommercetoolsAPIClient] - \
Get orders call finished at %s with total duration: %s", end_time, end_time - start_time)
logger.info("[UserOrdersView] Get CT orders call finished at %s with total duration: %s",
end_time, end_time - start_time)

return orders, customer

Expand Down
16 changes: 7 additions & 9 deletions commerce_coordinator/apps/commercetools/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def run_filter(self, request, params, order_data): # pylint: disable=arguments-
Returns:
"""
method_start_time = datetime.now()
log.info("[UserOrdersView] [GetCommercetoolsOrders] Starting pipeline step execution at %s", method_start_time)
log.info("[UserOrdersView] Starting CT orders pipeline step execution at %s", method_start_time)

if not is_redirect_to_commercetools_enabled_for_user(request):
return PipelineCommand.CONTINUE.value
Expand All @@ -61,32 +61,30 @@ def run_filter(self, request, params, order_data): # pylint: disable=arguments-

start_time = datetime.now()
log.info(
"[UserOrdersView] [GetCommercetoolsOrders] orders to attrs objects processing started at %s",
"[UserOrdersView] CT orders to attrs objects processing started at %s",
start_time
)
# noinspection PyTypeChecker
converted_orders = [attrs.asdict(order_from_commercetools(x, ct_orders[1]))
for x in ct_orders[0].results]
end_time = datetime.now()
log.info(
"[UserOrdersView] [GetCommercetoolsOrders] \
orders to attrs objects processing finished at %s with total duration: %s",
"[UserOrdersView] CT orders to attrs objects processing finished at %s with total duration: %s",
end_time, end_time - start_time
)

start_time = datetime.now()
log.info("[UserOrdersView] [GetCommercetoolsOrders] Orders rebuild call started at %s", start_time)
log.info("[UserOrdersView] CT orders rebuild call started at %s", start_time)
order_data.append(
ct_orders[0].rebuild(converted_orders)
)
end_time = datetime.now()
log.info("[UserOrdersView] [GetCommercetoolsOrders] \
Orders rebuild call finished at %s with total duration: %s", end_time, end_time - start_time)
log.info("[UserOrdersView] CT orders rebuild call finished at %s with total duration: %s",
end_time, end_time - start_time)

method_end_time = datetime.now()
log.info(
"[UserOrdersView] [GetCommercetoolsOrders] \
Completed pipeline step execution at %s with total duration: %s",
"[UserOrdersView] Completed CT pipeline step execution at %s with total duration: %s",
method_end_time, method_end_time - method_start_time
)
return {
Expand Down
5 changes: 2 additions & 3 deletions commerce_coordinator/apps/ecommerce/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ def get_orders(self, query_params):
resource_url = urljoin_directory(self.api_base_url, '/orders')
start_time = datetime.now()
logger.info(
'[UserOrdersView] [EcommerceAPIClient] - Legacy ecommerce get_orders API called at: %s',
'[UserOrdersView] Legacy ecommerce get_orders API called at: %s',
start_time
)
response = self.client.get(resource_url, params=query_params)
end_time = datetime.now()
logger.info(
'[UserOrdersView] [EcommerceAPIClient] \
- Legacy ecommerce get_orders API finished at: %s with total duration: %s',
'[UserOrdersView] Legacy ecommerce get_orders API finished at: %s with total duration: %s',
end_time, end_time - start_time
)
response.raise_for_status()
Expand Down
4 changes: 2 additions & 2 deletions commerce_coordinator/apps/ecommerce/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run_filter(self, request, params, order_data): # pylint: disable=arguments-
order_data: any preliminary orders (from an earlier pipeline step) we want to append to
"""
start_time = datetime.now()
log.info("[UserOrdersView] [GetEcommerceOrders] Starting pipeline step execution at %s", start_time)
log.info("[UserOrdersView] Starting Ecommerce pipeline step execution at %s", start_time)

new_params = params.copy()
# Ecommerce starts pagination from 1, other systems from 0, since the invoker assumes 0, we're always 1 off.
Expand All @@ -55,7 +55,7 @@ def run_filter(self, request, params, order_data): # pylint: disable=arguments-

end_time = datetime.now()
log.info(
"[UserOrdersView] [GetEcommerceOrders] Completed pipeline step execution at %s with total duration: %s",
"[UserOrdersView] Completed Ecommerce pipeline step execution at %s with total duration: %s",
end_time, end_time - start_time)
return {
"order_data": order_data
Expand Down
18 changes: 10 additions & 8 deletions commerce_coordinator/apps/frontend_app_ecommerce/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,26 @@ def get(self, request):
raise PermissionDenied(detail="Could not detect LMS user id.")

start_time = datetime.now()
logger.info("[UserOrdersView] Filter run started at: %s", start_time)
logger.info("[UserOrdersView] Pipline filter run started at: %s", start_time)
order_data = OrderHistoryRequested.run_filter(request, params)
end_time = datetime.now()
logger.info("[UserOrdersView] Filter run finished at: %s with total duration: %s", end_time,
logger.info("[UserOrdersView] Pipline filter run finished at: %s with total duration: %s", end_time,
end_time - start_time)

output_orders = []

start_time = datetime.now()
logger.info("[UserOrdersView] Looping through results starting at: %s", start_time)
logger.info("[UserOrdersView] Looping through combined orders results starting at: %s", start_time)
for order_set in order_data:
output_orders.extend(order_set['results'])

end_time = datetime.now()
logger.info("[UserOrdersView] Looping through results finished at: %s with total duration: %s",end_time,
end_time - start_time)
logger.info(
"[UserOrdersView] Looping through combined orders results finished at: %s with total duration: %s",
end_time, end_time - start_time)

start_time = datetime.now()
logger.info("[UserOrdersView] Sorting results for output starting at: %s", start_time)
logger.info("[UserOrdersView] Sorting combined orders results for output starting at: %s", start_time)
output = {
"count": request.query_params['page_size'], # This suppresses the ecomm mfe Order History Pagination ctrl
"next": None,
Expand All @@ -123,8 +124,9 @@ def get(self, request):
}

end_time = datetime.now()
logger.info("[UserOrdersView] Sorting results for output finished at: %s with total duration: %s",
end_time, end_time - start_time)
logger.info(
"[UserOrdersView] Sorting combined orders results for output finished at: %s with total duration: %s",
end_time, end_time - start_time)

request_end_time = datetime.now()
logger.info("[UserOrdersView] GET method finished at: %s with total duration: %s", request_end_time,
Expand Down

0 comments on commit d0a87e1

Please sign in to comment.