Skip to content

Commit

Permalink
Change logic for how to clear expired schedules
Browse files Browse the repository at this point in the history
Instead of clearing events that haven't started yet,
clear all events that haven't ended yet. In other words,
include currently running events in the candidates for deletion.
This avoids creating duplicates if the scheduler changes the current
event.
  • Loading branch information
timbeccue committed Dec 4, 2024
1 parent 3c3a334 commit dd1d937
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def deleteEventById(event, context):
print(f"userRoles: {userRoles}")

# Check if the requester is an admin
requesterIsAdmin="false"
if 'admin' in userRoles:
requesterIsAdmin="true"
requesterIsAdmin = 'admin' in userRoles
print(f"requesterIsAdmin: {requesterIsAdmin}")

# Specify the event with our pk (eventId) and sk (startTime)
Expand Down
12 changes: 5 additions & 7 deletions import_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ def clear_old_schedule(site, cutoff_time=None):
This method takes a site and a cutoff time, and deletes all events that satisfy the following conditions:
- the event belongs to the given site
- the event starts after the cutoff_time (specifically, the event start is greater than the cutoff_time)
- the event origin is 'lco'
- the event ends after the cutoff_time (specifically, the event end is greater than the cutoff_time)
- the event origin is 'LCO'
Then it gathers a list of project IDs that were associated with the deleted events, and delete them too.
Args:
cutoff_time (str):
Formatted yyyy-MM-ddTHH:mmZ (UTC, 24-hour format)
Any events that start before this time are not deleted.
Any events that end before this time are not deleted.
site (str):
Only delete events from the given site (e.g. 'mrc')
Expand All @@ -233,12 +233,10 @@ def clear_old_schedule(site, cutoff_time=None):


# Query items from the secondary index with 'site' as the partition key and 'end' greater than the specified end_date
# We're using 'end' time for the query because it's part of a pre-existing GSI that allows for efficient queries.
# But ultimately we want this to apply to events that start after the cutoff, so add that as a filter condition too.
query = calendar_table.query(
IndexName=index_name,
KeyConditionExpression=Key('site').eq(site) & Key('end').gt(cutoff_time),
FilterExpression=Attr('origin').eq('LCO') & Attr('start').gt(cutoff_time)
FilterExpression=Attr('origin').eq('LCO')
)
items = query.get('Items', [])
print(f"Removing expired scheduled events: {items}")
Expand All @@ -255,7 +253,7 @@ def clear_old_schedule(site, cutoff_time=None):
query = calendar_table.query(
IndexName=index_name,
KeyConditionExpression=Key('site').eq(site) & Key('end').gt(cutoff_time),
FilterExpression=Attr('origin').eq('lco') & Attr('start').gt(cutoff_time),
FilterExpression=Attr('origin').eq('LCO'),
ExclusiveStartKey=query['LastEvaluatedKey']
)
items = query.get('Items', [])
Expand Down

0 comments on commit dd1d937

Please sign in to comment.