diff options
author | Simon Rettberg | 2015-09-03 14:00:21 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-09-03 14:00:21 +0200 |
commit | 0c995060bb904c181f5ca58a2f2fbeb7c525d2cd (patch) | |
tree | fe12430fb4dd97794e4e376649f012aa45b6f02e /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java | |
parent | [client] removed unused interface implementation (diff) | |
download | tutor-module-0c995060bb904c181f5ca58a2f2fbeb7c525d2cd.tar.gz tutor-module-0c995060bb904c181f5ca58a2f2fbeb7c525d2cd.tar.xz tutor-module-0c995060bb904c181f5ca58a2f2fbeb7c525d2cd.zip |
[server] Improve mail handling, delete old lectures
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java')
-rw-r--r-- | dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java | 64 |
1 files changed, 64 insertions, 0 deletions
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 new file mode 100644 index 00000000..c0a5b65f --- /dev/null +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/maintenance/DeleteOldLectures.java @@ -0,0 +1,64 @@ +package org.openslx.bwlp.sat.maintenance; + +import java.sql.SQLException; +import java.util.concurrent.TimeUnit; + +import org.apache.log4j.Logger; +import org.joda.time.DateTime; +import org.openslx.bwlp.sat.database.mappers.DbLecture; +import org.openslx.util.QuickTimer; +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 = Logger.getLogger(DeleteOldLectures.class); + + private static final DeleteOldLectures instance = new DeleteOldLectures(); + + private static long blockedUntil = 0; + + /** + * Initialize the delete task. This schedules a timer that runs + * every 5 minutes. If the hour of day reaches 4, it will fire + * the task, and block it from running for the next 12 hours. + */ + public synchronized static void init() { + if (blockedUntil != 0) + return; + blockedUntil = 1; + QuickTimer.scheduleAtFixedRate(new Task() { + @Override + public void fire() { + if (blockedUntil > System.currentTimeMillis()) + return; + DateTime now = DateTime.now(); + if (now.getHourOfDay() != 4 || now.getMinuteOfHour() > 15) + return; + start(); + } + }, TimeUnit.MINUTES.toMillis(6), TimeUnit.MINUTES.toMillis(7)); + } + + public synchronized static void start() { + if (blockedUntil > System.currentTimeMillis()) + return; + if (Maintenance.trySubmit(instance)) { + blockedUntil = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(12); + } + } + + private DeleteOldLectures() { + } + + @Override + public void run() { + try { + DbLecture.deleteOld(365); + } catch (SQLException e) { + } + } + +} |