AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): handle notification service errors more elegently (#9734)
Nicholas Tindle6b7c8d5234dc
diff --git a/autogpt_platform/backend/backend/data/notifications.py b/autogpt_platform/backend/backend/data/notifications.pyindex 9f2fe3f323..8e42f2308a 100644--- a/autogpt_platform/backend/backend/data/notifications.py+++ b/autogpt_platform/backend/backend/data/notifications.py@@ -398,6 +398,8 @@ async def create_or_add_to_user_notification_batch(logger.info(f"Creating or adding to notification batch for {user_id} with type {notification_type} and data {notification_data}")+ if not notification_data.data:+ raise ValueError("Notification data must be provided")# Serialize the datajson_data: Json = Json(notification_data.data.model_dump())diff --git a/autogpt_platform/backend/backend/notifications/notifications.py b/autogpt_platform/backend/backend/notifications/notifications.pyindex 5210d47033..afa118e1bf 100644--- a/autogpt_platform/backend/backend/notifications/notifications.py+++ b/autogpt_platform/backend/backend/notifications/notifications.py@@ -245,20 +245,26 @@ class NotificationManager(AppService):continueunsub_link = generate_unsubscribe_link(batch.user_id)-- events = [- NotificationEventModel[- get_notif_data_type(db_event.type)- ].model_validate(- {- "user_id": batch.user_id,- "type": db_event.type,- "data": db_event.data,- "created_at": db_event.created_at,- }- )- for db_event in batch_data.notifications- ]+ events = []+ for db_event in batch_data.notifications:+ try:+ events.append(+ NotificationEventModel[+ get_notif_data_type(db_event.type)+ ].model_validate(+ {+ "user_id": batch.user_id,+ "type": db_event.type,+ "data": db_event.data,+ "created_at": db_event.created_at,+ }+ )+ )+ except Exception as e:+ logger.error(+ f"Error parsing notification event: {e=}, {db_event=}"+ )+ continuelogger.info(f"{events=}")self.email_sender.send_templated(@@ -668,6 +674,8 @@ class NotificationManager(AppService):except QueueEmpty:logger.debug(f"Queue {error_queue_name} empty")+ except TimeoutError:+ logger.debug(f"Queue {error_queue_name} timed out")except Exception as e:if message:logger.error(@@ -675,8 +683,8 @@ class NotificationManager(AppService):)self.run_and_wait(message.reject(requeue=False))else:- logger.error(- f"Error in notification service loop, message unable to be rejected, and will have to be manually removed to free space in the queue: {e}"+ logger.exception(+ f"Error in notification service loop, message unable to be rejected, and will have to be manually removed to free space in the queue: {e=}")def run_service(self):