diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-03-26 10:05:15 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-03-26 20:20:57 +0200 |
commit | b4125add7a55db6d2dc71a1bd0b2cadbe5ff7887 (patch) | |
tree | 6ab57882e38ac50b330add7358ae4c2c925002aa /server/sonar-ce | |
parent | 6b44584c0f1ecb30733493a0bf8f59120a6ed04b (diff) | |
download | sonarqube-b4125add7a55db6d2dc71a1bd0b2cadbe5ff7887.tar.gz sonarqube-b4125add7a55db6d2dc71a1bd0b2cadbe5ff7887.zip |
Fix issues with daylight saving time
Diffstat (limited to 'server/sonar-ce')
-rw-r--r-- | server/sonar-ce/src/main/java/org/sonar/ce/queue/PurgeCeActivities.java | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/queue/PurgeCeActivities.java b/server/sonar-ce/src/main/java/org/sonar/ce/queue/PurgeCeActivities.java index a7ee2c2e66f..aec3f85c76f 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/queue/PurgeCeActivities.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/queue/PurgeCeActivities.java @@ -19,10 +19,11 @@ */ package org.sonar.ce.queue; -import java.util.Calendar; +import java.util.Date; import java.util.Set; import org.sonar.api.Startable; import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; @@ -49,24 +50,19 @@ public class PurgeCeActivities implements Startable { @Override public void start() { try (DbSession dbSession = dbClient.openSession(false)) { - Calendar sixMonthsAgo = Calendar.getInstance(); - long now = system2.now(); - sixMonthsAgo.setTimeInMillis(now); - sixMonthsAgo.add(Calendar.DATE, -180); + Date sixMonthsAgo = DateUtils.addDays(new Date(system2.now()), -180); LOGGER.info("Delete the Compute Engine tasks created before {}", sixMonthsAgo.getTime()); - Set<String> ceActivityUuids = dbClient.ceActivityDao().selectOlderThan(dbSession, sixMonthsAgo.getTimeInMillis()) + Set<String> ceActivityUuids = dbClient.ceActivityDao().selectOlderThan(dbSession, sixMonthsAgo.getTime()) .stream() .map(CeActivityDto::getUuid) .collect(toSet()); dbClient.ceActivityDao().deleteByUuids(dbSession, ceActivityUuids); - Calendar fourWeeksAgo = Calendar.getInstance(); - fourWeeksAgo.setTimeInMillis(system2.now()); - fourWeeksAgo.add(Calendar.DATE, -28); + Date fourWeeksAgo = DateUtils.addDays(new Date(system2.now()), -28); LOGGER.info("Delete the Scanner contexts tasks created before {}", fourWeeksAgo.getTime()); - Set<String> scannerContextUuids = dbClient.ceScannerContextDao().selectOlderThan(dbSession, fourWeeksAgo.getTimeInMillis()); + Set<String> scannerContextUuids = dbClient.ceScannerContextDao().selectOlderThan(dbSession, fourWeeksAgo.getTime()); dbClient.ceScannerContextDao().deleteByUuids( dbSession, concat(ceActivityUuids.stream(), scannerContextUuids.stream()).collect(toSet())); |