2929import json
3030import os
3131from firebase_admin import messaging
32+ import logging
3233
3334# MARK: - Gym
3435
@@ -919,8 +920,19 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho
919920 for topic in topics :
920921 try :
921922 response = messaging .unsubscribe_from_topic (reminder .fcm_token , topic )
923+ logging .info (
924+ "Unsubscribe %s from %s -> success: %d failure: %d" ,
925+ reminder .fcm_token [:12 ],
926+ topic ,
927+ response .success_count ,
928+ response .failure_count ,
929+ )
930+ for error in response .errors :
931+ logging .warning (
932+ "Error unsubscribing %s from %s -> reason: %s" , reminder .fcm_token [:12 ], topic , error .reason
933+ )
922934 if response .success_count == 0 :
923- raise Exception (response .errors [0 ].reason )
935+ raise Exception (response .errors [0 ].reason )
924936 except Exception as error :
925937 raise GraphQLError (f"Error subscribing to topic: { error } " )
926938
@@ -930,8 +942,15 @@ def mutate(self, info, reminder_id, new_gyms, days_of_week, new_capacity_thresho
930942 for topic in topics :
931943 try :
932944 response = messaging .subscribe_to_topic (reminder .fcm_token , topic )
945+ logging .info (
946+ "Resubscribing %s to %s -> success: %d failure: %d" ,
947+ reminder .fcm_token [:12 ],
948+ topic ,
949+ response .success_count ,
950+ response .failure_count ,
951+ )
933952 if response .success_count == 0 :
934- raise Exception (response .errors [0 ].reason )
953+ raise Exception (response .errors [0 ].reason )
935954 except Exception as error :
936955 raise GraphQLError (f"Error subscribing to topic: { error } " )
937956
@@ -961,6 +980,13 @@ def mutate(self, info, reminder_id):
961980 for topic in topics :
962981 try :
963982 response = messaging .unsubscribe_from_topic (reminder .fcm_token , topic )
983+ logging .info (
984+ "Unsubscribe %s from %s -> success: %d failure: %d" ,
985+ reminder .fcm_token [:12 ],
986+ topic ,
987+ response .success_count ,
988+ response .failure_count ,
989+ )
964990 if response .success_count == 0 :
965991 raise Exception (response .errors [0 ].reason )
966992 except Exception as error :
0 commit comments