Skip to content

Commit 9824129

Browse files
committed
fix: logging en rare shit
1 parent c8e5005 commit 9824129

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/crud.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_user(db: Session, user: str):
1717

1818

1919
def create_announcement(db: Session, announcement: schemas.AnnouncementCreate):
20+
print(f"Sending notification {announcement.title} to {len(announcement.recipients)} users")
2021
recipients = []
2122
tokens = []
2223
for recipient in announcement.recipients:
@@ -25,17 +26,22 @@ def create_announcement(db: Session, announcement: schemas.AnnouncementCreate):
2526
for token in user.tokens:
2627
tokens.append(token.token)
2728

29+
print(f"Found {len(recipients)} registered users and {len(tokens)} relevant tokens")
2830
db_announcement = models.Announcement(title=announcement.title, description=announcement.description,
2931
content=announcement.content, recipients=recipients)
3032
db.add(db_announcement)
3133
db.commit()
3234
db.refresh(db_announcement)
3335

34-
requests.post("https://api.expo.dev/v2/push/send", json={
35-
"to": tokens,
36-
"title": announcement.title,
37-
"body": announcement.description
38-
}, timeout=10)
36+
for token in tokens:
37+
result = requests.post("https://exp.host/--/api/v2/push/send", json={
38+
"to": token,
39+
"title": announcement.title,
40+
"body": announcement.description
41+
}, timeout=10)
42+
if result.status_code != 200:
43+
print(f"Oeps, er ging iets mis {result.content}")
44+
3945
return db_announcement
4046

4147

0 commit comments

Comments
 (0)