Skip to content

Commit

Permalink
cleanup send push notif in update pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
voynow committed Nov 1, 2024
1 parent f34a999 commit fe0cb7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
15 changes: 15 additions & 0 deletions src/apn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import jwt
from dotenv import load_dotenv

from src.supabase_client import get_user_auth
from src.types.user_row import UserRow

load_dotenv()


Expand Down Expand Up @@ -72,3 +75,15 @@ def send_push_notification(device_token: str, title: str, body: str):
raise ValueError(f"APNs rejected the request: {error_payload}")

return response


def send_push_notif_wrapper(user: UserRow):
user_auth = get_user_auth(user.athlete_id)
if user_auth.device_token:
send_push_notification(
device_token=user_auth.device_token,
title="TrackFlow 🏃‍♂️🎯",
body="Your training week has been updated!",
)
else:
logger.info(f"Skipping push notification for {user.athlete_id=}")
18 changes: 3 additions & 15 deletions src/update_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
import traceback
from typing import Callable, Dict
from typing import Callable

from openai import APIResponse
from stravalib.client import Client
Expand All @@ -12,7 +12,7 @@
get_day_of_week_summaries,
get_weekly_summaries,
)
from src.apn import send_push_notification
from src.apn import send_push_notif_wrapper
from src.auth_manager import get_strava_client
from src.constants import COACH_ROLE
from src.email_manager import send_alert_email
Expand All @@ -22,7 +22,6 @@
get_training_week,
get_training_week_test,
get_user,
get_user_auth,
has_user_updated_today,
list_users,
upsert_training_week,
Expand All @@ -47,18 +46,7 @@ def training_week_update_pipeline(
strava_client = get_strava_client(user.athlete_id)
training_week = pipeline_function(user=user, strava_client=strava_client)
upsert_training_week(user.athlete_id, training_week)

user_auth = get_user_auth(user.athlete_id)
logger.info(f"User auth: {user_auth}")
if user_auth.device_token:
response = send_push_notification(
device_token=user_auth.device_token,
title="TrackFlow 🏃‍♂️🎯",
body="Your training week has been updated!",
)
logger.info(f"Push notification {response=}")
else:
logger.info(f"Skipping push notification for {user.athlete_id=}")
send_push_notif_wrapper(user)
return training_week


Expand Down

0 comments on commit fe0cb7e

Please sign in to comment.