-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
chore(notif-platform): Adds basic skeleton for notification service, fixes typing issues surrounding provider generics #93880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…fixes typing issues surrounding provider generics
def _send_notification( | ||
cls, | ||
*, | ||
notification_content: EmailRenderable, | ||
notification_type: NotificationType, | ||
target: NotificationTarget, | ||
thread_id: str | None = None, | ||
) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add doc comments, but this should handle actually sending the notification to the provider.
@staticmethod | ||
def notify_target( | ||
target: NotificationTarget, | ||
template: Any, | ||
data: Any, | ||
thread_id: str | None = None, | ||
) -> None: | ||
provider = provider_registry.get(target.provider_key) | ||
provider.dispatch_notification( | ||
target=target, template=template, data=data, thread_id=thread_id | ||
) | ||
|
||
@staticmethod | ||
def notify_many_targets( | ||
targets: list[NotificationTarget], | ||
template: Any, | ||
data: Any, | ||
thread_id: str | None = None, | ||
) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should queue tasks per target, but this showcases how to address the typing issues we saw before.
def dispatch_notification( | ||
cls, | ||
*, | ||
target: NotificationTarget, | ||
template: Any, | ||
data: Any, | ||
thread_id: str | None = None, | ||
) -> None: | ||
renderer = cls.get_renderer(notification_type=template.notification_type) | ||
notification_content = renderer.render(data=data, template=template) | ||
cls._send_notification( | ||
notification_content=notification_content, | ||
notification_type=template.notification_type, | ||
target=target, | ||
thread_id=thread_id, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows us to sidestep the generic type ambiguity issues we saw before, since we can guarantee the RenderableT
typing here via the cls
type.
default_renderer: NotificationRenderer[RenderableT] | ||
target_class: type[NotificationTarget] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added future annotations to alleviate this, though I'm not sure we needed quoted forward declarations for these before?
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #93880 +/- ##
===========================================
+ Coverage 64.03% 88.03% +24.00%
===========================================
Files 10333 10337 +4
Lines 596791 596930 +139
Branches 23196 23196
===========================================
+ Hits 382134 525534 +143400
+ Misses 214198 70937 -143261
Partials 459 459 |
WIP: Adds a shell for notification service, modifies typing for providers to account for generics, and type ambiguity when using them.