Skip to content

Commit

Permalink
feat: mine projects periodic random instead of full mining (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt committed Oct 27, 2022
1 parent 41899ae commit 7e91c1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -45,9 +46,16 @@ public class PeriodicMiner {
@Inject
Vertx vertx;

@Scheduled(every = "4h", delay = 3, delayUnit = TimeUnit.MINUTES)
void mineRepos() {
for (Project project : Project.<Project>findAll().list()) {
private Project getRandomProject() {
return Project.<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.<ProjectResult>request(
ServiceAdresses.PROJECT_REQUEST,
new ProjectRequest.WithUrl(project.getProjectUrl()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@
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;

/**
* This class is used to migrate the database to the latest version.
*/
@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();
Expand Down

0 comments on commit 7e91c1e

Please sign in to comment.