From 8325bb53cf188274a8a2a3c92714601b8b50b288 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Mon, 9 Feb 2026 23:25:52 +0000 Subject: [PATCH] added more logs --- backend/postcode_splitter/main.py | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/backend/postcode_splitter/main.py b/backend/postcode_splitter/main.py index e3a8c438..282e432a 100644 --- a/backend/postcode_splitter/main.py +++ b/backend/postcode_splitter/main.py @@ -176,8 +176,13 @@ def main(): def handler(event, context): + print("=" * 60) + print("HANDLER INVOKED") + print("=" * 60) print(f"Function: {context.function_name}") print(f"Request ID: {context.aws_request_id}") + print(f"Event received: {type(event)}") + print(f"Event keys: {event.keys() if isinstance(event, dict) else 'N/A'}") # Example SQS message for testing (copy and paste into SQS): # { @@ -186,24 +191,33 @@ def handler(event, context): # } # Handle both single event and batch events (SQS, etc.) + print("Extracting records from event...") records = event.get("Records", [event]) + print(f"Found {len(records)} record(s) to process") results = [] errors = [] + + print("Initializing SubTaskInterface...") subtask_interface = SubTaskInterface() + print("✓ SubTaskInterface initialized") for record in records: + print("Processing record...") task_id = None subtask_id = None try: # Parse body + print("Parsing body from record...") if isinstance(record.get("body"), str): body = json.loads(record["body"]) else: body = record.get("body", {}) + print(f"Body parsed: {body}") # Validate required fields task_id = body.get("task_id") s3_uri = body.get("s3_uri") + print(f"task_id: {task_id}, s3_uri: {s3_uri}") if not task_id: errors.append({"error": "Missing required field: task_id"}) @@ -214,13 +228,16 @@ def handler(event, context): continue # Convert task_id to UUID + print("Converting task_id to UUID...") try: task_id = UUID(task_id) if isinstance(task_id, str) else task_id + print(f"UUID conversion successful: {task_id}") except ValueError as e: errors.append({"error": f"Invalid UUID format for task_id: {str(e)}"}) continue # Create a new subtask for this postcode splitter invocation + print(f"Creating subtask for task {task_id}...") subtask_id = subtask_interface.create_subtask( task_id=task_id, inputs={"s3_uri": s3_uri} ) @@ -231,19 +248,26 @@ def handler(event, context): print(f"Processing s3_uri: {s3_uri}") # Read CSV from S3 - print("Reading CSV from S3...") + print("Parsing S3 URI...") bucket, key = parse_s3_console_url(s3_uri) - print(f"Parsed S3 - Bucket: {bucket}, Key: {key}") + print(f"Bucket: {bucket}, Key: {key}") + + print("Fetching CSV from S3...") csv_data = read_csv_from_s3_dict(bucket, key) + print(f"CSV fetched: {len(csv_data)} rows") + + print("Creating DataFrame...") df = pd.DataFrame(csv_data) - print(f"CSV loaded: {len(df)} rows, {len(df.columns)} columns") + print(f"DataFrame created: {len(df)} rows, {len(df.columns)} columns") # Get head for demo + print("Getting DataFrame head...") df_head = df.head() print("DataFrame head:") print(df_head) df_head_dict = df_head.to_dict("records") + print("Appending result...") results.append( { "message": "Postcode splitter processing started", @@ -252,8 +276,10 @@ def handler(event, context): "subtask_id": str(subtask_id), } ) + print("Result appended") # Mark subtask as complete after successful processing + print("Updating subtask status to complete...") subtask_interface.update_subtask_status( subtask_id, "complete",