Skip to content
Snippets Groups Projects
Commit 49ec05dd authored by David Trattnig's avatar David Trattnig
Browse files

Skip schedules in the past when deleting.

parent 383a074d
No related branches found
No related tags found
No related merge requests found
...@@ -108,29 +108,29 @@ class AuraCalendarService(threading.Thread): ...@@ -108,29 +108,29 @@ class AuraCalendarService(threading.Thread):
local_schedules = Schedule.select_programme(datetime.now()) local_schedules = Schedule.select_programme(datetime.now())
for local_schedule in local_schedules: for local_schedule in local_schedules:
# Only allow deletion of schedules which are before the start of the scheduling window # Only allow deletion of schedules which are deleted before the start of the scheduling window
if local_schedule.start_unix > now_unix and (local_schedule.start_unix - scheduling_window_start) > now_unix: if local_schedule.start_unix > now_unix:
if (local_schedule.start_unix - scheduling_window_start) > now_unix:
# Filter the local schedule from the fetched ones
existing_schedule = list(filter(lambda new_schedule: \ # Filter the local schedule from the fetched ones
new_schedule["schedule_id"] == local_schedule.schedule_id, fetched_schedule_data)) existing_schedule = list(filter(lambda new_schedule: \
new_schedule["schedule_id"] == local_schedule.schedule_id, fetched_schedule_data))
if existing_schedule:
# self.logger.debug("Schedule #%s is still existing remotely!" % (local_schedule.schedule_id)) if existing_schedule:
pass # self.logger.debug("Schedule #%s is still existing remotely!" % (local_schedule.schedule_id))
else: pass
self.logger.info("Schedule #%s has been deleted remotely, hence also delete it locally [%s]" % \ else:
(local_schedule.schedule_id, str(local_schedule))) self.logger.info("Schedule #%s has been deleted remotely, hence also delete it locally [%s]" % \
local_schedule.delete(commit=True) (local_schedule.schedule_id, str(local_schedule)))
self.logger.info("Deleted local schedule #%s from database" % local_schedule.schedule_id) local_schedule.delete(commit=True)
self.logger.info("Deleted local schedule #%s from database" % local_schedule.schedule_id)
else: else:
msg = "Schedule #%s has been deleted remotely. Since the scheduling window already started, it won't be deleted locally." % local_schedule.schedule_id msg = "Schedule #%s has been deleted remotely. Since the scheduling window has already started, it won't be deleted locally." % local_schedule.schedule_id
self.logger.warn(SimpleUtil.red(msg)) self.logger.warn(SimpleUtil.red(msg))
# Process fetched schedules # Process fetched schedules
for schedule in fetched_schedule_data: for schedule in fetched_schedule_data:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment