Skip to content

Commit

Permalink
More logging in price uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzevaka committed Oct 4, 2023
1 parent d6ae996 commit d14c906
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
4 changes: 2 additions & 2 deletions connect_ext_ppr/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def create_ppr(ppr, user_id, deployment, db, client, logger):
return new_ppr, file_instance, active_configuration

except DBAPIError as ex:
logger.error(ex)
logger.exception(ex)
db.rollback()
raise ExtensionHttpError.EXT_003()

Expand Down Expand Up @@ -390,7 +390,7 @@ def add_new_deployment_request(db, dr_data, deployment, account_id, logger):
db.commit()
return deployment_request
except DBAPIError as ex:
logger.error(ex)
logger.exception(ex)
db.rollback()
raise ExtensionHttpError.EXT_003()

Expand Down
47 changes: 44 additions & 3 deletions connect_ext_ppr/services/pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

from connect_ext_ppr.errors import PriceUpdateError
from connect_ext_ppr.client.exception import CBCClientError
from connect_ext_ppr.utils import execute_with_retry

from connect_ext_ppr.utils import execute_with_retry, create_dr_file_to_media

PRICELIST_COLUMNS = {
'MPN': str,
Expand Down Expand Up @@ -46,6 +45,7 @@ def apply_pricelist_to_marketplace(
cbc_service,
connect_client,
marketplace,
logger,
):
"""
@param DeploymentRequest deployment_request:
Expand All @@ -56,24 +56,63 @@ def apply_pricelist_to_marketplace(
@returns None
@raises ClientError, CBCClientError
"""
logger.info(
'Pricelist uploading %s_%s_%s: started.',
deployment_request.id,
marketplace.pricelist_id,
marketplace.marketplace,
)

reseller_id = _identify_reseller_id(
client=connect_client,
batch_id=marketplace.pricelist_id,
marketplace_id=marketplace.marketplace,
hub_id=deployment_request.deployment.hub_id,
)
logger.info(
'Pricelist uploading %s_%s_%s: reseller id %s.',
deployment_request.id,
marketplace.pricelist_id,
marketplace.marketplace,
reseller_id,
)
excel_file, file_name, dataset = _prepare_file(
client=connect_client,
batch_id=marketplace.pricelist_id,
)
create_dr_file_to_media(
client=connect_client,
account_id=deployment_request.deployment.account_id,
dr_id=deployment_request.id,
filename=file_name,
content=excel_file,
)
excel_file.seek(0)

logger.info(
'Pricelist uploading %s_%s_%s: filename "%s", dataset "%s".',
deployment_request.id,
marketplace.pricelist_id,
marketplace.marketplace,
file_name,
dataset,
)
try:
_process_batch(
data_id = _process_batch(
cbc_service=cbc_service,
excel_file=excel_file,
file_name=file_name,
reseller_id=reseller_id,
deployment=deployment_request.deployment,
dataset=dataset,
logger=logger,
)
logger.info(
'Pricelist uploading %s_%s_%s: data_id "%s".',
deployment_request.id,
marketplace.pricelist_id,
marketplace.marketplace,
data_id,
)
finally:
excel_file.close()
Expand Down Expand Up @@ -314,6 +353,7 @@ def _process_batch(
reseller_id,
deployment,
dataset,
logger,
):
excel_file.seek(0)

Expand All @@ -322,6 +362,7 @@ def _process_batch(
exception_class=CBCClientError,
args=(reseller_id, deployment.vendor_id, excel_file),
)
logger.info('Parsed price: %s', parsed_price)

data_id = parsed_price['dataId']

Expand Down
4 changes: 4 additions & 0 deletions connect_ext_ppr/tasks_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def apply_pricelist_task(
connect_client,
marketplace,
db,
logger,
**kwargs,
):
""" Applies a price list for a sinle marketplace
Expand All @@ -285,6 +286,7 @@ def apply_pricelist_task(
@param Client connect_client:
@param MarketplaceConfiguration marketplace:
@param Session db:
@param Logger logger:
@returns bool
@raises TaskException
Expand All @@ -296,6 +298,7 @@ def apply_pricelist_task(
cbc_service,
connect_client,
marketplace,
logger,
)
except (ClientError, CBCClientError) as e:
raise TaskException(f'Error while processing pricelist: {e}')
Expand Down Expand Up @@ -417,6 +420,7 @@ def execute_tasks(db, config, tasks, connect_client, logger):
connect_client=connect_client,
marketplace=task.marketplace,
db=db,
logger=logger,
)
task.status = TasksStatusChoices.done

Expand Down

0 comments on commit d14c906

Please sign in to comment.