Skip to content

Commit

Permalink
switch earliest and latest date to make it consistent, fix stream ite…
Browse files Browse the repository at this point in the history
…rate
  • Loading branch information
julian-christl committed Sep 17, 2024
1 parent 006560e commit 490483b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ Optional<ProgrammingExerciseStudentParticipation> findWithSubmissionsByExerciseI
JOIN TREAT (participation.exercise AS ProgrammingExercise) pe
WHERE participation.repositoryUri IS NOT NULL
AND (
(pe.dueDate IS NOT NULL AND :latestDate <= pe.dueDate AND pe.dueDate <= :earliestDate)
OR (pe.exerciseGroup IS NOT NULL AND :latestDate <= pe.exerciseGroup.exam.endDate AND pe.exerciseGroup.exam.endDate <= :earliestDate)
(pe.dueDate IS NOT NULL AND :earliestDate <= pe.dueDate AND pe.dueDate <= :latestDate)
OR (pe.exerciseGroup IS NOT NULL AND :earliestDate <= pe.exerciseGroup.exam.endDate AND pe.exerciseGroup.exam.endDate <= :latestDate)
)
""")
Page<String> findRepositoryUrisForGitCleanupByRecentDueDateOrRecentExamEndDate(@Param("earliestDate") ZonedDateTime earliestDate, @Param("latestDate") ZonedDateTime latestDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ public void cleanupGitWorkingCopiesOnArtemisServer() {
SecurityUtils.setAuthorizationObject();
log.info("Cleanup git repositories on Artemis server");
// we are specifically interested in exercises older than 8 weeks
var earliestDate = ZonedDateTime.now().minusWeeks(8).truncatedTo(ChronoUnit.DAYS);
var latestDate = ZonedDateTime.now().minusWeeks(8).truncatedTo(ChronoUnit.DAYS);
// NOTE: for now we would like to cover more cases to also cleanup older repositories
var latestDate = earliestDate.minusYears(1).truncatedTo(ChronoUnit.DAYS);
var earliestDate = latestDate.minusYears(1).truncatedTo(ChronoUnit.DAYS);

// Cleanup all student repos in the REPOS folder (based on the student participations) 8 weeks after the exercise due date or exam end date
cleanStudentParticipationsRepositories(earliestDate, latestDate);

// Cleanup template, tests and solution repos in the REPOS folder 8 weeks after the course or exam is over
log.info("Search for exercises with course or exam date from {} until {}", latestDate, earliestDate);
var programmingExercises = programmingExerciseRepository.findAllByRecentCourseEndDate(latestDate, earliestDate);
programmingExercises.addAll(programmingExerciseRepository.findAllByRecentExamEndDate(latestDate, earliestDate));
log.info("Search for exercises with course or exam date from {} until {}", earliestDate, latestDate);
var programmingExercises = programmingExerciseRepository.findAllByRecentCourseEndDate(earliestDate, latestDate);
programmingExercises.addAll(programmingExerciseRepository.findAllByRecentExamEndDate(earliestDate, latestDate));
log.info("Found {} programming exercise to clean local template, test and solution: {}", programmingExercises.size(),
programmingExercises.stream().map(ProgrammingExercise::getProjectKey).collect(Collectors.joining(", ")));
if (!programmingExercises.isEmpty()) {
Expand All @@ -128,18 +128,16 @@ public void cleanupGitWorkingCopiesOnArtemisServer() {
}

private void cleanStudentParticipationsRepositories(ZonedDateTime earliestDate, ZonedDateTime latestDate) {
log.info("Search for exercises with due date from {} until {}", latestDate, earliestDate);
log.info("Search for exercises with due date from {} until {}", earliestDate, latestDate);
// Get all relevant participation ids
Pageable pageable = Pageable.ofSize(STUDENT_PARTICIPATION_CLEANUP_BATCH_SIZE);
Page<String> uriBatch = programmingExerciseStudentParticipationRepository.findRepositoryUrisForGitCleanupByRecentDueDateOrRecentExamEndDate(earliestDate, latestDate,
pageable);
log.info("Found {} student participations to clean local student repositories in {} batches.", uriBatch.getTotalElements(), uriBatch.getTotalPages());
if (uriBatch.getTotalElements() > 0) {
var ignored = Stream.iterate(uriBatch, Page::hasNext, page -> {
page.forEach(this::deleteLocalRepositoryByUriString);
return programmingExerciseStudentParticipationRepository.findRepositoryUrisForGitCleanupByRecentDueDateOrRecentExamEndDate(earliestDate, latestDate,
page.nextPageable());
});
var batchStream = Stream.iterate(uriBatch, Page::hasNext, page -> programmingExerciseStudentParticipationRepository
.findRepositoryUrisForGitCleanupByRecentDueDateOrRecentExamEndDate(earliestDate, latestDate, page.nextPageable()));
batchStream.forEach(page -> page.forEach(this::deleteLocalRepositoryByUriString));
log.info("Finished cleaning local student repositories");
}
}
Expand Down

0 comments on commit 490483b

Please sign in to comment.