diff options
author | Simon Rettberg | 2022-11-07 14:09:21 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-11-07 14:09:21 +0100 |
commit | 1a86fd07a650f6e614a58611923b4b7b42d8c9ec (patch) | |
tree | 3e544020d03e6ad8e4a848f385085a3bb236f246 | |
parent | [server] Try to catch weird bug when deleting old images (diff) | |
download | tutor-module-1a86fd07a650f6e614a58611923b4b7b42d8c9ec.tar.gz tutor-module-1a86fd07a650f6e614a58611923b4b7b42d8c9ec.tar.xz tutor-module-1a86fd07a650f6e614a58611923b4b7b42d8c9ec.zip |
[server] Add start/finished log output to recurring maintenance tasks
5 files changed, 17 insertions, 3 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java index 7fde3310..ab9d3343 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/mappers/DbLecture.java @@ -649,16 +649,18 @@ public class DbLecture { } } - public static void deleteOld(int minAgeDays) throws SQLException { + public static int deleteOld(int minAgeDays) throws SQLException { + int cnt = 0; try (MysqlConnection connection = Database.getConnection()) { MysqlStatement stmt = connection.prepareStatement("DELETE FROM lecture WHERE endtime < :cutoff"); stmt.setLong("cutoff", Util.unixTime() - TimeUnit.DAYS.toSeconds(minAgeDays)); - stmt.executeUpdate(); + cnt = stmt.executeUpdate(); connection.commit(); } catch (SQLException e) { LOGGER.error("Query failed in DbLecture.deleteOld()", e); throw e; } + return cnt; } public static List<LectureSummary> getLecturesUsingImageVersion(MysqlConnection connection, String imageVersionId) diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldImages.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldImages.java index c99133aa..b255e885 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldImages.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldImages.java @@ -66,6 +66,7 @@ public class DeleteOldImages implements Runnable { @Override public void run() { // Get all images currently marked as "Should delete" and reset them to "keep" + LOGGER.info("Marking old/expired images for deletion..."); Set<String> resetList; try { resetList = DbImage.resetDeleteState(); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java index fb093ea7..d4018fd5 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java @@ -3,6 +3,8 @@ package org.openslx.bwlp.sat.maintenance; import java.sql.SQLException; import java.util.concurrent.TimeUnit; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.joda.time.DateTime; import org.openslx.bwlp.sat.database.mappers.DbLecture; import org.openslx.util.QuickTimer; @@ -12,6 +14,8 @@ import org.openslx.util.QuickTimer.Task; * Delete old image versions (images that reached their expire time). */ public class DeleteOldLectures implements Runnable { + + private static final Logger LOGGER = LogManager.getLogger(DeleteOldLectures.class); private static final DeleteOldLectures instance = new DeleteOldLectures(); @@ -52,10 +56,13 @@ public class DeleteOldLectures implements Runnable { @Override public void run() { + LOGGER.info("Deleting expired lectures..."); + int cnt = 0; try { - DbLecture.deleteOld(365); + cnt = DbLecture.deleteOld(365); } catch (SQLException e) { } + LOGGER.info("Deleted " + cnt + "lectures"); } } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldUsers.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldUsers.java index c3a1da57..579333bb 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldUsers.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldUsers.java @@ -57,6 +57,7 @@ public class DeleteOldUsers implements Runnable { @Override public void run() { + LOGGER.info("Deleting inactive users with no remaining lectures or VMs..."); List<UserInfo> inactiveUsers; try { inactiveUsers = DbUser.getInactive(); @@ -73,6 +74,7 @@ public class DeleteOldUsers implements Runnable { // Already logged } } + LOGGER.info("Done deleting old users"); } } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/SendExpireWarning.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/SendExpireWarning.java index 2bfb0508..5ef935d0 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/SendExpireWarning.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/SendExpireWarning.java @@ -57,8 +57,10 @@ public class SendExpireWarning implements Runnable { @Override public void run() { + LOGGER.info("Scanning for expiring lectures and VMs to send mail reminders..."); checkImages(); checkLectures(); + LOGGER.info("Done scanning for expired lectures/VMs"); } private void checkLectures() { |