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

"You're Going OnCall" mobile app push notification #1814

Merged
merged 17 commits into from
May 4, 2023

Conversation

joeyorlando
Copy link
Contributor

@joeyorlando joeyorlando commented Apr 24, 2023

What this PR does

https://www.loom.com/share/c5deb35309604cfdab6176c44de7b15e

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • CHANGELOG.md updated (or pr:no changelog PR label added if not required)

@joeyorlando joeyorlando requested a review from a team April 24, 2023 17:21
Copy link
Contributor

@Dieterbe Dieterbe left a comment

Choose a reason for hiding this comment

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

i can't review the python code, but in principle, LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this looks like a bigger diff than it actually is. I extracted the logic that is now in the following methods to avoid having to duplicate w/ the addition of this new push notification:

  • send_push_notification_to_fcm_relay
  • _send_push_notification
  • _construct_fcm_message

@joeyorlando joeyorlando marked this pull request as ready for review May 2, 2023 16:27
@joeyorlando joeyorlando requested a review from a team May 2, 2023 16:27
@joeyorlando joeyorlando changed the title add info_notifications_enabled column to user mobile app settings "You're Going OnCall" mobile app push notification May 2, 2023
Copy link
Contributor

@matiasb matiasb left a comment

Choose a reason for hiding this comment

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

Makes sense, minor comments/questions added 👍



ScheduleEvents = List[ScheduleEvent]
ScheduleEventIntervals = List[List[datetime.datetime]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍

engine/apps/mobile_app/tasks.py Outdated Show resolved Hide resolved
engine/apps/mobile_app/tasks.py Outdated Show resolved Hide resolved
def should_we_send_going_oncall_push_notification(
now: timezone.datetime, user_settings: "MobileAppUserSettings", schedule_event: ScheduleEvent
) -> bool:
NOTIFICATION_TIMING_BUFFER = 15 * 60 # 15 minutes in seconds
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the task is scheduled to run every 10 mins, is it possible we may send 2 notifications for the same user/shift combination?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point 👍 I ended up storing a key in redis for ~80mins to keep track of these notifications (change) and avoid duplicates

@joeyorlando joeyorlando added the pr:no public docs Added to a PR that does not require public documentation updates label May 4, 2023
@joeyorlando
Copy link
Contributor Author

discussed w/ @grafana/grafana-oncall-mobile, we will document this feature in a forthcoming PR

Copy link
Contributor

@matiasb matiasb left a comment

Choose a reason for hiding this comment

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

LGTM, 2 last questions added.

logger.info("not sending going oncall push notification because info_notifications_enabled is false")
return

# 8 minute window where the notification could be sent (4 mins before or 4 mins after)
Copy link
Contributor

Choose a reason for hiding this comment

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

if we run the task every 10 mins, shouldn't the window cover (at least) 10 mins?

schedule_final_events = schedule.final_events("UTC", now, days=7)

relevant_cache_keys = [
_generate_going_oncall_push_notification_cache_key(user["pk"], schedule_event, current_date_with_hour)
Copy link
Contributor

Choose a reason for hiding this comment

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

edge case, but using current_date_with_hour couldn't still lead to duplicates? (e.g. my shift starts at 16:02?) wouldn't be enough to use user and event keys? (and caching the key for 1h)

@joeyorlando joeyorlando enabled auto-merge May 4, 2023 16:53
@joeyorlando joeyorlando added this pull request to the merge queue May 4, 2023
Merged via the queue into dev with commit 620f69e May 4, 2023
@joeyorlando joeyorlando deleted the jorlando/youre-oncall-push-notification branch May 4, 2023 17:05
iskhakov pushed a commit that referenced this pull request May 12, 2023
# What this PR does

https://www.loom.com/share/c5deb35309604cfdab6176c44de7b15e

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:no public docs Added to a PR that does not require public documentation updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants