Skip to content
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

Make new client per IOS notif #335

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions backend/user/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@

@staticmethod
def get_client(is_dev):
# TODO: We are getting a new client for each request, might be worth
# looking into how to keep the client alive.
auth_key_path = (
f"/app/secrets/notifications/ios{'/dev/apns-dev' if is_dev else '/prod/apns-prod'}.pem"
)
return APNsClient(credentials=auth_key_path, use_sandbox=is_dev)

def __init__(self, is_dev=False):
try:
self.client = self.get_client(is_dev)
self.is_dev = is_dev
self.topic = "org.pennlabs.PennMobile" + (".dev" if is_dev else "")
except Exception as e:
print(f"Notifications Error: Failed to initialize APNs client: {e}")
Expand All @@ -126,10 +128,12 @@

def send_many_notifications(self, tokens, payload):
notifications = [Notification(token, payload) for token in tokens]
self.client.send_notification_batch(notifications=notifications, topic=self.topic)
self.get_client(self.is_dev).send_notification_batch(

Check warning on line 131 in backend/user/notifications.py

View check run for this annotation

Codecov / codecov/patch

backend/user/notifications.py#L131

Added line #L131 was not covered by tests
notifications=notifications, topic=self.topic
)

def send_one_notification(self, token, payload):
self.client.send_notification(token, payload, self.topic)
self.get_client(self.is_dev).send_notification(token, payload, self.topic)

Check warning on line 136 in backend/user/notifications.py

View check run for this annotation

Codecov / codecov/patch

backend/user/notifications.py#L136

Added line #L136 was not covered by tests


IOSNotificationSender = IOSNotificationWrapper()
Expand Down
Loading