Skip to content

Commit

Permalink
Fix daily noti failed cause missing fcm_token, send_all is deprecated (
Browse files Browse the repository at this point in the history
…#1601)

```
Error querying chunk ['Africa/Abidjan', 'Africa/Accra', 'Africa/Bamako', 'Africa/Banjul', 'Africa/Bissau', 'Africa/Conakry', 'Africa/Dakar', 'Africa/Freetown', 'Africa/Lome', 'Africa/Monrovia', 'Africa/Nouakchott', 'Africa/Ouagadougou', 'Africa/Sao_Tome', 'Africa/Timbuktu', 'America/Danmarkshavn', 'Antarctica/Troll', 'Atlantic/Canary', 'Atlantic/Faeroe', 'Atlantic/Faroe', 'Atlantic/Madeira', 'Atlantic/Reykjavik', 'Atlantic/St_Helena', 'Eire', 'Etc/GMT', 'Etc/GMT+0', 'Etc/GMT-0', 'Etc/GMT0', 'Etc/Greenwich', 'Etc/UCT', 'Etc/UTC']: "'fcm_token' is not contained in the data"
```

```
Error sending message: Unexpected HTTP response with status: 404; body: <!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/batch</code> was not found on this server.  <ins>That’s all we know.</ins>
  ```
  • Loading branch information
beastoin authored Dec 29, 2024
2 parents 478cba3 + 8f6d5b5 commit 6e32a57
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion backend/database/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def sync_query():
try:
query = users_ref.where(filter=FieldFilter('time_zone', 'in', chunk))
for doc in query.stream():
if (filter == 'fcm_token'):
if 'fcm_token' not in doc.to_dict():
continue
if filter == 'fcm_token':
token = doc.get('fcm_token')
else:
token = doc.id, doc.get('fcm_token')
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def send_batch(batch_users):
token=token
) for token in batch_users
]
return messaging.send_all(messages)
return messaging.send_each(messages)

tasks = []
for i in range(num_batches):
Expand Down
4 changes: 2 additions & 2 deletions backend/utils/other/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ async def _send_bulk_summary_notification(users: list):

async def send_daily_notification():
try:
morning_alert_title = "Don\'t forget to wear Friend today"
morning_alert_body = "Wear your friend and capture your memories today."
morning_alert_title = "Don\'t forget to wear Omi today"
morning_alert_body = "Wear your omi and capture your memories today."
morning_target_time = "08:00"

await _send_notification_for_time(morning_target_time, morning_alert_title, morning_alert_body)
Expand Down

0 comments on commit 6e32a57

Please sign in to comment.