Conversion import returns faster and processes in the background
This commit is contained in:
@@ -1410,14 +1410,32 @@ async def handle_xml_upload(
|
||||
filename,
|
||||
)
|
||||
|
||||
# Process the conversion XML and save to database
|
||||
# Process the conversion XML in the background
|
||||
async def process_in_background():
|
||||
"""Process conversion XML asynchronously in the background."""
|
||||
try:
|
||||
# Use SessionMaker for concurrent processing of large XML files
|
||||
# This allows multiple reservations to be processed in parallel with independent sessions
|
||||
# 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)
|
||||
processing_stats = await conversion_service.process_conversion_xml(
|
||||
xml_content
|
||||
)
|
||||
|
||||
_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 = {
|
||||
@@ -1425,25 +1443,17 @@ async def handle_xml_upload(
|
||||
"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>
|
||||
<status>success</status>
|
||||
<message>Conversion data processed successfully</message>
|
||||
<stats>
|
||||
<totalReservations>{processing_stats["total_reservations"]}</totalReservations>
|
||||
<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>
|
||||
<status>accepted</status>
|
||||
<message>XML file received and queued for processing</message>
|
||||
<filename>{filename}</filename>
|
||||
<timestamp>{datetime.now().isoformat()}</timestamp>
|
||||
</response>"""
|
||||
|
||||
return Response(
|
||||
content=response_content, headers=response_headers, status_code=200
|
||||
content=response_content, headers=response_headers, status_code=202
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
|
||||
Reference in New Issue
Block a user