From 9dd82c963de85d2ce7d422017d5fa9f6d44b9b63 Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Wed, 1 Oct 2025 16:49:01 -0400 Subject: [PATCH 1/5] topic subscription logic --- src/schema.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/schema.py b/src/schema.py index 21dfdc0..365e902 100644 --- a/src/schema.py +++ b/src/schema.py @@ -863,7 +863,9 @@ def mutate(self, info, fcm_token, days_of_week, gyms, capacity_percent): for day in validated_workout_days: topic_name = f"{gym}_{day}_{capacity_percent}" try: - messaging.subscribe_to_topic(fcm_token, topic_name) + response = messaging.subscribe_to_topic(fcm_token, topic_name) + if response.success_count == 0: + raise Exception(response.errors[0].reason) except Exception as error: raise GraphQLError(f"Error subscribing to topic for {topic_name}: {error}") From 03192c855638ab859023d46fd584911372ce4544 Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Wed, 1 Oct 2025 17:07:57 -0400 Subject: [PATCH 2/5] other subscription logic --- src/schema.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/schema.py b/src/schema.py index 365e902..46ff774 100644 --- a/src/schema.py +++ b/src/schema.py @@ -918,7 +918,9 @@ def mutate(self, info, reminder_id, gyms, days_of_week, capacity_percent): for topic in topics: try: - messaging.unsubscribe_from_topic(reminder.fcm_token, topic) + response = messaging.unsubscribe_from_topic(reminder.fcm_token, topic) + if response.success_count == 0: + raise Exception(response.errors[0].reason) except Exception as error: raise GraphQLError(f"Error subscribing to topic: {error}") @@ -927,7 +929,9 @@ def mutate(self, info, reminder_id, gyms, days_of_week, capacity_percent): for topic in topics: try: - messaging.subscribe_to_topic(reminder.fcm_token, topic) + response = messaging.subscribe_to_topic(reminder.fcm_token, topic) + if response.success_count == 0: + raise Exception(response.errors[0].reason) except Exception as error: raise GraphQLError(f"Error subscribing to topic: {error}") @@ -956,7 +960,9 @@ def mutate(self, info, reminder_id): for topic in topics: try: - messaging.unsubscribe_from_topic(reminder.fcm_token, topic) + response = messaging.unsubscribe_from_topic(reminder.fcm_token, topic) + if response.success_count == 0: + raise Exception(response.errors[0].reason) except Exception as error: raise GraphQLError(f"Error unsubscribing from topic {topic}: {error}") From 8f2ba4d5918288d02b52cbe74c05ab842d8aae1d Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Wed, 1 Oct 2025 18:12:24 -0400 Subject: [PATCH 3/5] fix log formatting + rollback error --- src/scrapers/capacities_scraper.py | 32 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/scrapers/capacities_scraper.py b/src/scrapers/capacities_scraper.py index 7e6157b..9d55c6d 100644 --- a/src/scrapers/capacities_scraper.py +++ b/src/scrapers/capacities_scraper.py @@ -1,5 +1,6 @@ import requests import time +import logging from bs4 import BeautifulSoup from collections import namedtuple from datetime import datetime @@ -71,7 +72,7 @@ def fetch_capacities(): # Map API name to database name if facility_name not in CAPACITY_MARKER_NAMES: - print(f"Warning: No name mapping for facility: {facility_name}") + logging.info(f"Warning: No name mapping for facility: {facility_name}") continue db_name = CAPACITY_MARKER_NAMES[facility_name] @@ -100,24 +101,33 @@ def fetch_capacities(): facility = Facility.query.filter_by(id=facility_id).first() if not facility or not facility.hours: - print(f"Warning: No hours found for facility ID {facility_id}") + logging.info(f"Warning: No hours found for facility ID {facility_id}") continue current_time = int(time.time()) - + is_open = any(hour.start_time <= current_time <= hour.end_time for hour in facility.hours) + + logging.info("nicole: before send notif") if is_open: topic_enum = gym_mapping[db_name] check_and_send_capacity_reminders(topic_enum.name, db_name, percent, last_percent) - + + logging.info("nicole: after send notif") + + logging.info("nicole: before add single cap") + add_single_capacity(count, facility_id, percent, updated) + + logging.info("nicole: after add single cap") except Exception as e: - print(f"Error processing facility {facility.get('LocationName', 'unknown')}: {str(e)}") - + logging.exception(f"Error processing facility {facility.get('LocationName', 'unknown')}: {str(e)}") + db_session.rollback() + except Exception as e: - print(f"Error fetching capacities: {str(e)}") + logging.error(f"Error fetching capacities: {str(e)}") raise @@ -177,10 +187,10 @@ def update_hourly_capacity(curDay, curHour): ) if hourly_average_capacity is not None: - print("updating average") + logging.info("updating average") hourly_average_capacity.update_hourly_average(capacity.percent) else: - print("No hourly capacity, creating new entry") + logging.info("No hourly capacity, creating new entry") hourly_average_capacity = HourlyAverageCapacity( facility_id=capacity.facility_id, average_percent=capacity.percent, @@ -193,7 +203,7 @@ def update_hourly_capacity(curDay, curHour): db_session.commit() except Exception as e: - print(f"Error updating hourly average: {e}") + logging.error(f"Error updating hourly average: {e}") def check_and_send_capacity_reminders(facility_name, readable_name, current_percent, last_percent): @@ -214,5 +224,5 @@ def check_and_send_capacity_reminders(facility_name, readable_name, current_perc for threshold in crossed_thresholds: topic_name = f"{facility_name}_{current_day_name}_{threshold}" - print(f"Sending message to devices subscribed to {topic_name}") + logging.info(f"Sending message to devices subscribed to {topic_name}") send_capacity_reminder(topic_name, readable_name, threshold) From 585b414fbd1ed221c2032f6392be4d150a339cd1 Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Thu, 2 Oct 2025 10:12:44 -0400 Subject: [PATCH 4/5] logs --- src/scrapers/capacities_scraper.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scrapers/capacities_scraper.py b/src/scrapers/capacities_scraper.py index 9d55c6d..15400bd 100644 --- a/src/scrapers/capacities_scraper.py +++ b/src/scrapers/capacities_scraper.py @@ -108,23 +108,23 @@ def fetch_capacities(): is_open = any(hour.start_time <= current_time <= hour.end_time for hour in facility.hours) - logging.info("nicole: before send notif") + logging.info("rollback error: before send notif") if is_open: topic_enum = gym_mapping[db_name] check_and_send_capacity_reminders(topic_enum.name, db_name, percent, last_percent) - logging.info("nicole: after send notif") + logging.info("rollback error: after send notif") - logging.info("nicole: before add single cap") + logging.info("rollback error: before add single cap") add_single_capacity(count, facility_id, percent, updated) - logging.info("nicole: after add single cap") + logging.info("rollback error: after add single cap") except Exception as e: logging.exception(f"Error processing facility {facility.get('LocationName', 'unknown')}: {str(e)}") - db_session.rollback() + # db_session.rollback() except Exception as e: logging.error(f"Error fetching capacities: {str(e)}") From 63753903935da3ede64bed324ce608abbc0fcccf Mon Sep 17 00:00:00 2001 From: Nicole Qiu Date: Wed, 8 Oct 2025 17:22:58 -0400 Subject: [PATCH 5/5] remove logging for release branch --- src/scrapers/capacities_scraper.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/scrapers/capacities_scraper.py b/src/scrapers/capacities_scraper.py index 15400bd..bd0998a 100644 --- a/src/scrapers/capacities_scraper.py +++ b/src/scrapers/capacities_scraper.py @@ -108,20 +108,12 @@ def fetch_capacities(): is_open = any(hour.start_time <= current_time <= hour.end_time for hour in facility.hours) - logging.info("rollback error: before send notif") - if is_open: topic_enum = gym_mapping[db_name] check_and_send_capacity_reminders(topic_enum.name, db_name, percent, last_percent) - - logging.info("rollback error: after send notif") - - logging.info("rollback error: before add single cap") add_single_capacity(count, facility_id, percent, updated) - logging.info("rollback error: after add single cap") - except Exception as e: logging.exception(f"Error processing facility {facility.get('LocationName', 'unknown')}: {str(e)}") # db_session.rollback()