@@ -938,58 +938,68 @@ def existing_events_for_schedule(
938938 if external_connection is None or external_connection .token is None :
939939 raise RemoteCalendarConnectionError ()
940940
941- # Create a single connector for this batch of calendars
942- con = GoogleConnector (
943- db = db ,
944- redis_instance = redis ,
945- google_client = google_client ,
946- remote_calendar_id = google_calendars [0 ].user , # This isn't used for get_busy_time but is still needed.
947- calendar_id = google_calendars [0 ].id , # This isn't used for get_busy_time but is still needed.
948- subscriber_id = subscriber .id ,
949- google_tkn = external_connection .token ,
950- )
951-
952- # Batch all calendar IDs for this connection into a single API call
953- calendar_ids = [calendar .user for calendar in google_calendars ]
954- existing_events .extend (
955- [
956- schemas .Event (start = busy .get ('start' ), end = busy .get ('end' ), title = 'Busy' )
957- for busy in con .get_busy_time (calendar_ids , start .strftime (DATEFMT ), end .strftime (DATEFMT ))
958- ]
959- )
960-
961- # Process CalDAV calendars individually (no batching support)
962- for calendar in caldav_calendars :
963- con = CalDavConnector (
964- db = db ,
965- redis_instance = redis ,
966- url = calendar .url ,
967- user = calendar .user ,
968- password = calendar .password ,
969- subscriber_id = subscriber .id ,
970- calendar_id = calendar .id ,
971- )
972-
973941 try :
942+ # Create a single connector for this batch of calendars
943+ con = GoogleConnector (
944+ db = db ,
945+ redis_instance = redis ,
946+ google_client = google_client ,
947+ remote_calendar_id = google_calendars [0 ].user , # Not used for get_busy_time but needed.
948+ calendar_id = google_calendars [0 ].id , # Not used for get_busy_time but needed.
949+ subscriber_id = subscriber .id ,
950+ google_tkn = external_connection .token ,
951+ )
952+
953+ # Batch all calendar IDs for this connection into a single API call
954+ calendar_ids = [calendar .user for calendar in google_calendars ]
974955 existing_events .extend (
975956 [
976957 schemas .Event (start = busy .get ('start' ), end = busy .get ('end' ), title = 'Busy' )
977- for busy in con .get_busy_time ([ calendar . url ] , start .strftime (DATEFMT ), end .strftime (DATEFMT ))
958+ for busy in con .get_busy_time (calendar_ids , start .strftime (DATEFMT ), end .strftime (DATEFMT ))
978959 ]
979960 )
961+ except RemoteCalendarConnectionError :
962+ raise
963+ except Exception as e :
964+ logging .warning (f'[Tools.existing_events_for_schedule] Google Calendar connection error: { e } ' )
965+ raise RemoteCalendarConnectionError ()
980966
981- # We're good here, continue along the loop
982- continue
983- except caldav .lib .error .ReportError :
984- logging .debug ('[Tools.existing_events_for_schedule] CalDAV server does not support FreeBusy API.' )
985- pass
986-
987- # Okay maybe this server doesn't support freebusy, try the old way
967+ # Process CalDAV calendars individually (no batching support)
968+ for calendar in caldav_calendars :
988969 try :
970+ con = CalDavConnector (
971+ db = db ,
972+ redis_instance = redis ,
973+ url = calendar .url ,
974+ user = calendar .user ,
975+ password = calendar .password ,
976+ subscriber_id = subscriber .id ,
977+ calendar_id = calendar .id ,
978+ )
979+
980+ try :
981+ busy_times = con .get_busy_time (
982+ [calendar .url ], start .strftime (DATEFMT ), end .strftime (DATEFMT )
983+ )
984+ existing_events .extend (
985+ [
986+ schemas .Event (start = busy .get ('start' ), end = busy .get ('end' ), title = 'Busy' )
987+ for busy in busy_times
988+ ]
989+ )
990+
991+ # We're good here, continue along the loop
992+ continue
993+ except caldav .lib .error .ReportError :
994+ logging .debug ('[Tools.existing_events_for_schedule] CalDAV server does not support FreeBusy API.' )
995+
996+ # Okay maybe this server doesn't support freebusy, try the old way
989997 existing_events .extend (con .list_events (start .strftime (DATEFMT ), end .strftime (DATEFMT )))
990- except requests .exceptions .ConnectionError :
991- # Connection error with remote caldav calendar, don't crash this route.
992- pass
998+ except RemoteCalendarConnectionError :
999+ raise
1000+ except Exception as e :
1001+ logging .warning (f'[Tools.existing_events_for_schedule] CalDAV connection error: { e } ' )
1002+ raise RemoteCalendarConnectionError ()
9931003
9941004 # handle already requested time slots
9951005 for slot in schedule .slots :
0 commit comments