Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jzwang8
Copy link
Collaborator

@jzwang8 jzwang8 commented Jul 30, 2020

Files changed:

  • ParticipantDatastore: Add method to return list of unmatched participants
  • RemoveExpiredParticipantsServlet: Remove expired participants from datastore when called
  • cron.xml: add cron job to call doGet of RemoveExpiredParticipantsServlet every 1 hour

(Same as PR #84 except this one includes only the correct files)

Copy link
Collaborator

@kmh287 kmh287 left a 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());
Copy link
Collaborator

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

Comment on lines +41 to +53
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);
Copy link
Collaborator

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-

@jzwang8 jzwang8 marked this pull request as draft July 31, 2020 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove expired Participants from datastore with cron job
2 participants