Conversion import returns faster and processes in the background
This commit is contained in:
@@ -1410,14 +1410,32 @@ async def handle_xml_upload(
|
|||||||
filename,
|
filename,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Process the conversion XML and save to database
|
# Process the conversion XML in the background
|
||||||
# Use SessionMaker for concurrent processing of large XML files
|
async def process_in_background():
|
||||||
# This allows multiple reservations to be processed in parallel with independent sessions
|
"""Process conversion XML asynchronously in the background."""
|
||||||
conversion_service = ConversionService(session_maker)
|
try:
|
||||||
processing_stats = await conversion_service.process_conversion_xml(xml_content)
|
# Use SessionMaker for concurrent processing of large XML files
|
||||||
|
# This allows multiple reservations to be processed
|
||||||
|
# in parallel with independent sessions
|
||||||
|
conversion_service = ConversionService(session_maker)
|
||||||
|
processing_stats = await conversion_service.process_conversion_xml(
|
||||||
|
xml_content
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Conversion processing complete for %s: %s", filename, processing_stats
|
"Conversion processing complete for %s: %s",
|
||||||
|
filename,
|
||||||
|
processing_stats,
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
_LOGGER.exception(
|
||||||
|
"Error processing conversion XML in background for %s", filename
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create background task and add done callback for error logging
|
||||||
|
task = asyncio.create_task(process_in_background())
|
||||||
|
task.add_done_callback(
|
||||||
|
lambda t: t.exception() if not t.cancelled() else None
|
||||||
)
|
)
|
||||||
|
|
||||||
response_headers = {
|
response_headers = {
|
||||||
@@ -1425,25 +1443,17 @@ async def handle_xml_upload(
|
|||||||
"X-AlpineBits-Server-Accept-Encoding": "gzip",
|
"X-AlpineBits-Server-Accept-Encoding": "gzip",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return processing stats in response
|
# Return immediate acknowledgment
|
||||||
response_content = f"""<?xml version="1.0" encoding="UTF-8"?>
|
response_content = f"""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<response>
|
<response>
|
||||||
<status>success</status>
|
<status>accepted</status>
|
||||||
<message>Conversion data processed successfully</message>
|
<message>XML file received and queued for processing</message>
|
||||||
<stats>
|
<filename>{filename}</filename>
|
||||||
<totalReservations>{processing_stats["total_reservations"]}</totalReservations>
|
<timestamp>{datetime.now().isoformat()}</timestamp>
|
||||||
<deletedReservations>{processing_stats["deleted_reservations"]}</deletedReservations>
|
|
||||||
<totalDailySales>{processing_stats["total_daily_sales"]}</totalDailySales>
|
|
||||||
<matchedToReservation>{processing_stats["matched_to_reservation"]}</matchedToReservation>
|
|
||||||
<matchedToCustomer>{processing_stats["matched_to_customer"]}</matchedToCustomer>
|
|
||||||
<matchedToHashedCustomer>{processing_stats["matched_to_hashed_customer"]}</matchedToHashedCustomer>
|
|
||||||
<unmatched>{processing_stats["unmatched"]}</unmatched>
|
|
||||||
<errors>{processing_stats["errors"]}</errors>
|
|
||||||
</stats>
|
|
||||||
</response>"""
|
</response>"""
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
content=response_content, headers=response_headers, status_code=200
|
content=response_content, headers=response_headers, status_code=202
|
||||||
)
|
)
|
||||||
|
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
|
|||||||
Reference in New Issue
Block a user