Skip to content

Commit

Permalink
Development: Improve cleanup schedule for build logs
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Sep 9, 2024
1 parent aaa6837 commit d9f2cb8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ public class BuildLogEntryService {

private final ProgrammingSubmissionRepository programmingSubmissionRepository;

private final ProfileService profileService;

@Value("${artemis.continuous-integration.build-log.file-expiry-days:30}")
private int expiryDays;

@Value("${artemis.build-logs-path:./build-logs}")
private Path buildLogsPath;

public BuildLogEntryService(BuildLogEntryRepository buildLogEntryRepository, ProgrammingSubmissionRepository programmingSubmissionRepository) {
public BuildLogEntryService(BuildLogEntryRepository buildLogEntryRepository, ProgrammingSubmissionRepository programmingSubmissionRepository, ProfileService profileService) {
this.buildLogEntryRepository = buildLogEntryRepository;
this.programmingSubmissionRepository = programmingSubmissionRepository;
this.profileService = profileService;
}

/**
Expand Down Expand Up @@ -331,10 +334,30 @@ public FileSystemResource retrieveBuildLogsFromFileForBuildJob(String buildJobId
}

/**
* Deletes all build log files that are older than {@link #expiryDays} days on a schedule
* Scheduled task that deletes old build log files from the continuous integration system.
* <p>
* This method runs based on the cron schedule defined in the application properties, with
* a default value of 3:00 AM every day if no custom schedule is provided.
* The task will only execute if scheduling is active, which is checked via the {@code profileService}.
* </p>
* <p>
* The method iterates through the files in the configured build logs directory and deletes
* files that were last modified before the configured expiry period (in days). The expiration
* period is specified by the {@code expiryDays} variable, and files older than this period are deleted.
* </p>
* <p>
* In case of an error during file deletion, it logs the error and continues processing.
* </p>
*
* @throws IOException if an I/O error occurs while accessing the build log files directory or
* deleting files.
*/
@Scheduled(cron = "${artemis.continuous-integration.build-log.cleanup-schedule:0 0 3 1 * ?}")
@Scheduled(cron = "${artemis.continuous-integration.build-log.cleanup-schedule:0 0 3 * * ?}")
public void deleteOldBuildLogsFiles() {
// only execute this if scheduling is active
if (!profileService.isSchedulingActive()) {
return;
}
log.info("Deleting old build log files");
ZonedDateTime now = ZonedDateTime.now();

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config/application-artemis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ artemis:
notification-plugin: "ls1tum/artemis-notification-plugin:1.0.0" # Docker image for the generic notification plugin. This value is set in an CI variable in GitLab CI.
build-log:
file-expiry-days: 30 # The amount of days until build log files can be deleted
cleanup-schedule: 0 0 3 1 * ? # Cron expression for schedule to delete old build log files
cleanup-schedule: 0 0 3 * * ? # Cron expression for schedule to delete old build log files
git:
name: Artemis
email: artemis@xcit.tum.de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,6 @@ void filterOutEmptyLogs() {
assertThat(result).isEmpty();
}

private List<BuildLogEntry> convertToBuildLogs(List<String> content) {
return convertToBuildLogs(content.stream());
}

private List<BuildLogEntry> convertToBuildLogs(String... content) {
return convertToBuildLogs(Arrays.stream(content));
}
Expand Down

0 comments on commit d9f2cb8

Please sign in to comment.