You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some of the code paths in the notification & scheduler service were synchronous HTTP calls that execute a long-running job that blocks. This makes the service threads busy waiting.
Changes ποΈ
Remove queue_notification API
Remove DTO
Move heavy tasks intothe executor
Checklist π
For code changes:
I have clearly listed my changes in the PR description
I have made a test plan
I have tested my changes according to the test plan:
Manually executing notification service jobs through the scheduler API
The new queue_notification and queue_notification_async functions have similar error handling but don't follow the same pattern as the service methods they replace. Consider standardizing error handling across these functions.
defqueue_notification(event: NotificationEventModel) ->NotificationResult:
"""Queue a notification - exposed method for other services to call"""try:
logger.debug(f"Received Request to queue {event=}")
exchange="notifications"routing_key=get_routing_key(event.type)
queue=get_notification_queue()
queue.publish_message(
routing_key=routing_key,
message=event.model_dump_json(),
exchange=next(exforexinEXCHANGESifex.name==exchange),
)
returnNotificationResult(
success=True,
message=f"Notification queued with routing key: {routing_key}",
)
exceptExceptionase:
logger.exception(f"Error queueing notification: {e}")
returnNotificationResult(success=False, message=str(e))
asyncdefqueue_notification_async(event: NotificationEventModel) ->NotificationResult:
"""Queue a notification - exposed method for other services to call"""try:
logger.debug(f"Received Request to queue {event=}")
exchange="notifications"routing_key=get_routing_key(event.type)
queue=awaitget_async_notification_queue()
awaitqueue.publish_message(
routing_key=routing_key,
message=event.model_dump_json(),
exchange=next(exforexinEXCHANGESifex.name==exchange),
)
returnNotificationResult(
success=True,
message=f"Notification queued with routing key: {routing_key}",
)
exceptExceptionase:
logger.exception(f"Error queueing notification: {e}")
returnNotificationResult(success=False, message=str(e))
The background_executor is shared globally but there's no clear lifecycle management. Consider adding proper initialization and shutdown for the ThreadPoolExecutor to prevent resource leaks.
The queue_notification and queue_notification_async functions share almost identical code. Consider refactoring to reduce duplication by extracting common logic into a shared helper function.
defqueue_notification(event: NotificationEventModel) ->NotificationResult:
"""Queue a notification - exposed method for other services to call"""try:
logger.debug(f"Received Request to queue {event=}")
exchange="notifications"routing_key=get_routing_key(event.type)
queue=get_notification_queue()
queue.publish_message(
routing_key=routing_key,
message=event.model_dump_json(),
exchange=next(exforexinEXCHANGESifex.name==exchange),
)
returnNotificationResult(
success=True,
message=f"Notification queued with routing key: {routing_key}",
)
exceptExceptionase:
logger.exception(f"Error queueing notification: {e}")
returnNotificationResult(success=False, message=str(e))
asyncdefqueue_notification_async(event: NotificationEventModel) ->NotificationResult:
"""Queue a notification - exposed method for other services to call"""try:
logger.debug(f"Received Request to queue {event=}")
exchange="notifications"routing_key=get_routing_key(event.type)
queue=awaitget_async_notification_queue()
awaitqueue.publish_message(
routing_key=routing_key,
message=event.model_dump_json(),
exchange=next(exforexinEXCHANGESifex.name==exchange),
)
returnNotificationResult(
success=True,
message=f"Notification queued with routing key: {routing_key}",
)
exceptExceptionase:
logger.exception(f"Error queueing notification: {e}")
returnNotificationResult(success=False, message=str(e))
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some of the code paths in the notification & scheduler service were synchronous HTTP calls that execute a long-running job that blocks. This makes the service threads busy waiting.
Changes ποΈ
Checklist π
For code changes: