2929import json
3030import os
3131from firebase_admin import messaging
32+ import logging
33+
34+
35+ def resolve_enum_value (entry ):
36+ """Return the raw value for Enum objects while leaving plain strings untouched."""
37+ return getattr (entry , "value" , entry )
3238
3339# MARK: - Gym
3440
@@ -913,14 +919,25 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho
913919
914920 # Unsubscribe from old reminders
915921 topics = [
916- f"{ gym } _{ day } _{ reminder .capacity_threshold } " for gym in reminder .gyms for day in reminder .days_of_week
922+ f"{ resolve_enum_value (gym )} _{ resolve_enum_value (day )} _{ reminder .capacity_threshold } "
923+ for gym in reminder .gyms
924+ for day in reminder .days_of_week
917925 ]
918926
919927 for topic in topics :
920928 try :
921929 response = messaging .unsubscribe_from_topic (reminder .fcm_token , topic )
930+ logging .info (
931+ "Unsubscribe %s from %s" ,
932+ reminder .fcm_token [:12 ],
933+ topic ,
934+ )
935+ for error in response .errors :
936+ logging .warning (
937+ "Error unsubscribing %s from %s -> reason: %s" , reminder .fcm_token [:12 ], topic , error .reason
938+ )
922939 if response .success_count == 0 :
923- raise Exception (response .errors [0 ].reason )
940+ raise Exception (response .errors [0 ].reason )
924941 except Exception as error :
925942 raise GraphQLError (f"Error subscribing to topic: { error } " )
926943
@@ -930,8 +947,13 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho
930947 for topic in topics :
931948 try :
932949 response = messaging .subscribe_to_topic (reminder .fcm_token , topic )
950+ logging .info (
951+ "Resubscribing %s to %s" ,
952+ reminder .fcm_token [:12 ],
953+ topic ,
954+ )
933955 if response .success_count == 0 :
934- raise Exception (response .errors [0 ].reason )
956+ raise Exception (response .errors [0 ].reason )
935957 except Exception as error :
936958 raise GraphQLError (f"Error subscribing to topic: { error } " )
937959
@@ -955,12 +977,19 @@ def mutate(self, info, reminder_id):
955977 raise GraphQLError ("CapacityReminder not found." )
956978
957979 topics = [
958- f"{ gym } _{ day } _{ reminder .capacity_threshold } " for gym in reminder .gyms for day in reminder .days_of_week
980+ f"{ resolve_enum_value (gym )} _{ resolve_enum_value (day )} _{ reminder .capacity_threshold } "
981+ for gym in reminder .gyms
982+ for day in reminder .days_of_week
959983 ]
960984
961985 for topic in topics :
962986 try :
963987 response = messaging .unsubscribe_from_topic (reminder .fcm_token , topic )
988+ logging .info (
989+ "Unsubscribe %s from %s" ,
990+ reminder .fcm_token [:12 ],
991+ topic ,
992+ )
964993 if response .success_count == 0 :
965994 raise Exception (response .errors [0 ].reason )
966995 except Exception as error :
0 commit comments