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

PP-483 Added last notified date to loan and hold models #1464

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

RishiDiwanTT
Copy link
Contributor

@RishiDiwanTT RishiDiwanTT commented Oct 16, 2023

Description

This allows us to run the notification scripts multiple times a day without bombarding the same patron multiple times with the same content.
The notifications code updates the timestamp every time a notification is sent out, and the script queries incorporate the new column.

Motivation and Context

Currently, the push notification scripts only run once per day.
This is because additional runs would send out duplicate notifications.
We need to add some way of disallowing the notification from going out twice.
JIRA

How Has This Been Tested?

Updated the unit tests to cover the new cases.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

This allows us to run the notification scripts multiple times a day
without bombarding the same patron multiple times with the same content
@RishiDiwanTT RishiDiwanTT added DB migration This PR contains a DB migration feature New feature labels Oct 16, 2023
@RishiDiwanTT RishiDiwanTT requested a review from a team October 16, 2023 11:15
@RishiDiwanTT RishiDiwanTT self-assigned this Oct 16, 2023
@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (1961cd2) 90.38% compared to head (7acac73) 90.38%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1464   +/-   ##
=======================================
  Coverage   90.38%   90.38%           
=======================================
  Files         233      233           
  Lines       29700    29710   +10     
  Branches     6787     6793    +6     
=======================================
+ Hits        26843    26853   +10     
  Misses       1824     1824           
  Partials     1033     1033           
Flag Coverage Δ
Api 74.07% <25.00%> (-0.02%) ⬇️
Core 60.94% <100.00%> (+0.01%) ⬆️
migration 28.90% <25.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
core/jobs/holds_notification.py 96.29% <100.00%> (+0.29%) ⬆️
core/model/patron.py 97.97% <100.00%> (+0.01%) ⬆️
core/util/notifications.py 90.90% <100.00%> (+0.47%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple minor comments on this one:

  1. Maybe we should set the notified field after we've successfully sent a notification, so that we gracefully retry in the case of a transient failure from firebase.
  2. Since the ticket is to run the scripts more often, we should probably update the cron schedule in this PR as well.

@@ -135,6 +136,7 @@ def send_loan_expiry_message(
f"Patron {loan.patron.authorization_identifier} has {len(tokens)} device tokens. "
f"Sending loan expiry notification(s)."
)
loan.patron_last_notified = utc_now().date()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If firebase gives us a transient exception in send_messages, this might cause the notification to be dropped, instead of retried on the next script run. Since we set the notification date before we know that we sent a message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated both instances of the code to only update the patron_last_notified if at least one notification was sent successfully.

@@ -204,6 +206,7 @@ def send_holds_notifications(cls, holds: list[Hold]) -> list[str]:
if hold.patron.authorization_identifier:
data["authorization_identifier"] = hold.patron.authorization_identifier

hold.patron_last_notified = utc_now().date()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about when we set the notified date as above.

@RishiDiwanTT RishiDiwanTT merged commit 480d0f9 into main Oct 18, 2023
30 checks passed
@RishiDiwanTT RishiDiwanTT deleted the feature/multiple-notification-runs branch October 18, 2023 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DB migration This PR contains a DB migration feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants