55import os
66import logging
77from datetime import datetime , timezone , timedelta
8+ from idp_common .models import Document
89
910logger = logging .getLogger ()
1011logger .setLevel (os .environ .get ('LOG_LEVEL' , 'INFO' ))
@@ -25,12 +26,26 @@ def lambda_handler(event, context):
2526 """
2627 logger .info (f"Processing event: { json .dumps (event )} " )
2728
28- # Extract document information
29- document = event .get ('Payload' , {}).get ('Result' , {}).get ('document' , {})
30- if not document :
31- document = event .get ('Payload' , {}).get ('ProcessingResult' , {}).get ('document' , {})
32- if not document :
33- document = event .get ('Payload' , {}).get ('document' , {})
29+ # Extract document information using load_document to handle compression
30+ document_data = event .get ('Payload' , {}).get ('Result' , {}).get ('document' , {})
31+ if not document_data :
32+ document_data = event .get ('Payload' , {}).get ('ProcessingResult' , {}).get ('document' , {})
33+ if not document_data :
34+ document_data = event .get ('Payload' , {}).get ('document' , {})
35+
36+ # Get working bucket for decompression
37+ working_bucket = os .environ .get ('WORKING_BUCKET' )
38+ if not working_bucket :
39+ logger .warning ("WORKING_BUCKET environment variable not set" )
40+
41+ # Load document using utility method to handle compression/decompression
42+ try :
43+ document_obj = Document .load_document (document_data , working_bucket , logger )
44+ # Convert back to dict for the rest of the function
45+ document = document_obj .to_dict ()
46+ except Exception as e :
47+ logger .error (f"Error loading document: { str (e )} " )
48+ raise
3449
3550 document_id = document .get ('id' )
3651 workflow_execution_arn = document .get ('workflow_execution_arn' )
@@ -185,4 +200,4 @@ def store_token_in_tracking_table(table, token_id, task_token, document_id, exec
185200 table .put_item (Item = item )
186201 logger .info (f"Stored token information: { token_id } " )
187202 except Exception as e :
188- logger .error (f"Error storing token { token_id } : { str (e )} " )
203+ logger .error (f"Error storing token { token_id } : { str (e )} " )
0 commit comments