diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java index 056c8ade3..e55309e60 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java @@ -1,6 +1,7 @@ package io.github.martinwitt.laughing_train.mining; import com.google.common.flogger.FluentLogger; +import com.mongodb.client.model.Aggregates; import io.github.martinwitt.laughing_train.data.AnalyzerRequest; import io.github.martinwitt.laughing_train.data.ProjectRequest; import io.github.martinwitt.laughing_train.data.ProjectResult; @@ -45,9 +46,16 @@ public class PeriodicMiner { @Inject Vertx vertx; - @Scheduled(every = "4h", delay = 3, delayUnit = TimeUnit.MINUTES) - void mineRepos() { - for (Project project : Project.findAll().list()) { + private Project getRandomProject() { + return Project.mongoCollection() + .aggregate(List.of(Aggregates.sample(1))) + .first(); + } + + @Scheduled(every = "15m", delay = 3, delayUnit = TimeUnit.MINUTES) + void mineRandomRepo() { + Project project = getRandomProject(); + if (project != null) { eventBus.request( ServiceAdresses.PROJECT_REQUEST, new ProjectRequest.WithUrl(project.getProjectUrl()), diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java index 8380c6f4a..cf97acbd5 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/persistence/DataBaseMigration.java @@ -3,10 +3,13 @@ import com.mongodb.client.model.Filters; import io.quarkus.mongodb.panache.PanacheMongoEntityBase; import io.quarkus.runtime.StartupEvent; +import io.vertx.core.Vertx; import java.util.ArrayList; import java.util.Map; +import java.util.concurrent.TimeUnit; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Observes; +import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; /** @@ -14,10 +17,21 @@ */ @ApplicationScoped public class DataBaseMigration { + @Inject + Vertx vertx; /** * This method is called by the quarkus framework to migrate the database. */ public void onStart(@Observes StartupEvent event) { + migrateDataBase(); + checkPeroidic(); + } + + public void checkPeroidic() { + vertx.setPeriodic(TimeUnit.MINUTES.toMillis(30), id -> migrateDataBase()); + } + + private void migrateDataBase() { removeBadSmellsWithoutPosition(); removeProjectHashesWithoutResults(); removeBadSmellsWithoutIdentifier();