From fe0cb7ea42648ccb050ded18367b80f334c816e0 Mon Sep 17 00:00:00 2001 From: voynow Date: Fri, 1 Nov 2024 07:51:31 -0400 Subject: [PATCH] cleanup send push notif in update pipeline --- src/apn.py | 15 +++++++++++++++ src/update_pipeline.py | 18 +++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/apn.py b/src/apn.py index cfd5ade..8fb04b9 100644 --- a/src/apn.py +++ b/src/apn.py @@ -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() @@ -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=}") diff --git a/src/update_pipeline.py b/src/update_pipeline.py index bebe68d..e7de42a 100644 --- a/src/update_pipeline.py +++ b/src/update_pipeline.py @@ -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 @@ -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 @@ -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, @@ -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