-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add servlet for cron job to remove expired participants #85
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test
|
||
List<Entity> results = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults()); | ||
List<Participant> participants = | ||
results.stream().map(p -> getParticipantFromEntity(p)).collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: p -> getParticipantFromEntity(p)
can instead be a method reference this::getParticipantFromEntity
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
System.out.println("Remove expired participants"); | ||
|
||
List<Participant> unmatchedParticipants = participantDatastore.getUnmatchedParticipants(); | ||
|
||
// Check if match exists and not returned yet | ||
for (Participant participant : unmatchedParticipants) { | ||
if (isExpired(participant)) { | ||
participantDatastore.removeParticipant(participant.getUsername()); | ||
return; | ||
} | ||
} | ||
response.setStatus(HttpServletResponse.SC_OK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continuing from the other PR:
I think you may be able to delete a batch of entries at once, which would be helpful if we could query datastore for unmatched AND endTimeAvailable. Or else we'd have to loop through the list of unmatchedParticipants and create another list of the ones who are unmatched and expired. I couldn't find detailed documentation about that operation, though. And I was hesitant to try out querying by endTimeAvailable since I had so much trouble doing that last time--I wanted to see if the cron job works before optimizing the query.
I agree that the query is sufficient for now. But at this step, it would still make sense to delete all of the expired participants in one delete operation instead of one transaction per participant.
https://cloud.google.com/appengine/docs/standard/java/javadoc/com/google/appengine/api/datastore/DatastoreService.html#delete-java.lang.Iterable-
Files changed:
(Same as PR #84 except this one includes only the correct files)