import java.util.Calendar;
import java.util.Set;
+import org.sonar.api.Startable;
import org.sonar.api.ce.ComputeEngineSide;
-import org.sonar.api.platform.Server;
-import org.sonar.api.platform.ServerStartHandler;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.db.ce.CeActivityDto;
@ComputeEngineSide
-public class PurgeCeActivities implements ServerStartHandler {
+public class PurgeCeActivities implements Startable {
private static final Logger LOGGER = Loggers.get(PurgeCeActivities.class);
}
@Override
- public void onServerStart(Server server) {
+ public void start() {
try (DbSession dbSession = dbClient.openSession(false)) {
Calendar sixMonthsAgo = Calendar.getInstance();
sixMonthsAgo.setTimeInMillis(system2.now());
dbSession.commit();
}
}
+
+ @Override
+ public void stop() {
+ // nothing to do
+ }
}
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.platform.Server;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeTaskTypes;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
insertWithDate("RECENT", 1_500_000_000_000L);
when(system2.now()).thenReturn(1_500_000_000_100L);
- underTest.onServerStart(mock(Server.class));
+ underTest.start();
assertThat(dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), "VERY_OLD").isPresent()).isFalse();
assertThat(dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), "RECENT").isPresent()).isTrue();