LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
fix: Added traceback for log publisher related errors (#1184)
Chandrasekharan Mc4e92033e56a
diff --git a/unstract/core/src/unstract/core/pubsub_helper.py b/unstract/core/src/unstract/core/pubsub_helper.pyindex 602627705..fdcf7ab78 100644--- a/unstract/core/src/unstract/core/pubsub_helper.py+++ b/unstract/core/src/unstract/core/pubsub_helper.py@@ -1,6 +1,8 @@import jsonimport loggingimport os+import time+import tracebackfrom datetime import datetime, timezonefrom typing import Any, Optional@@ -125,12 +127,10 @@ class LogPublisher:@classmethoddef publish(cls, channel_id: str, payload: dict[str, Any]) -> bool:- channel = f"logs:{channel_id}""""Publish a message to the queue."""try:-+ event = f"logs:{channel_id}"with cls.kombu_conn.Producer(serializer="json") as producer:- event = f"logs:{channel_id}"task_message = cls._get_task_message(user_session_id=channel_id,event=event,@@ -147,16 +147,41 @@ class LogPublisher:retry=True,)logging.debug(f"Published '{channel_id}' <= {payload}")- log_data = json.dumps(payload)- # Check if the payload type is "LOG"- if payload["type"] == "LOG":- logs_expiration = os.environ.get(- "LOGS_EXPIRATION_TIME_IN_SECOND", 86400- ) # Defaults to 1 day- timestamp = payload["timestamp"]- redis_key = f"{channel}:{timestamp}"- cls.r.setex(redis_key, logs_expiration, log_data)++ # Persisting messages for unified notification+ if payload.get("type") == "LOG":+ cls.store_for_unified_notification(event, payload)except Exception as e:- logging.error(f"Failed to publish '{channel_id}' <= {payload}: {e}")+ logging.error(+ f"Failed to publish '{channel_id}' <= {payload}"+ f": {e}\n{traceback.format_exc()}"+ )return Falsereturn True++ @classmethod+ def store_for_unified_notification(+ cls, event: str, payload: dict[str, Any]+ ) -> None:+ """Helps persist messages for unified notification.++ Message is stored in redis with a configurable TTL.+ Will be used to display such messages in the UI.++ Args:+ event (str): User session ID+ payload (dict[str, Any]): Message being sent+ """+ try:+ logs_expiration = os.environ.get(+ "LOGS_EXPIRATION_TIME_IN_SECOND", "86400"+ ) # Defaults to 1 day+ timestamp = payload.get("timestamp", round(time.time(), 6))+ redis_key = f"{event}:{timestamp}"+ log_data = json.dumps(payload)+ cls.r.setex(redis_key, logs_expiration, log_data)+ except Exception as e:+ logging.error(+ f"Failed to store unified notification log for '{event}' "+ f"<= {payload}: {e}\n{traceback.format_exc()}"+ )