Skip to content

Commit

Permalink
fix(spoon): Mark SpoonMiner as @unremovable (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Jul 10, 2023
1 parent a0dd546 commit 7431304
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.github.martinwitt.laughing_train.services.ProjectService;
import io.github.martinwitt.laughing_train.services.QodanaService;
import io.micrometer.core.instrument.MeterRegistry;
import io.quarkus.arc.Unremovable;
import io.quarkus.runtime.StartupEvent;
import io.vertx.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -28,6 +29,7 @@
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;

@Unremovable
@ApplicationScoped
public class QodanaPeriodicMiner {

Expand Down Expand Up @@ -76,11 +78,13 @@ private Project getKnownProject() {
}

void mine(@Observes StartupEvent event) {
logger.atInfo().log("Starting Qodana periodic miner");
vertx.setTimer(TimeUnit.MINUTES.toMillis(5), v -> vertx.executeBlocking(it -> mineRandomRepo()));
}

private void mineRandomRepo() {
try {
logger.atInfo().log("Mining repository with qodana");
var project = queue.isEmpty() ? getRandomProject() : queue.poll();
var checkoutResult = checkoutProject(project);
if (checkoutResult instanceof ProjectResult.Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import io.github.martinwitt.laughing_train.domain.entity.Project;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.github.martinwitt.laughing_train.services.ProjectService;
import io.github.martinwitt.laughing_train.services.QodanaService;
import io.github.martinwitt.laughing_train.services.SpoonAnalyzerService;
import io.micrometer.core.instrument.MeterRegistry;
import io.quarkus.arc.Unremovable;
import io.quarkus.runtime.StartupEvent;
import io.vertx.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -26,6 +26,7 @@
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;

@Unremovable
@ApplicationScoped
public abstract class SpoonPeriodicMiner {

Expand All @@ -46,7 +47,6 @@ public SpoonPeriodicMiner(
Vertx vertx,
SearchProjectService searchProjectService,
ProjectRepository projectRepository,
QodanaService qodanaService,
ProjectService projectService,
MiningPrinter miningPrinter,
SpoonAnalyzerService spoonAnalyzerService) {
Expand All @@ -73,19 +73,20 @@ private Project getKnownProject() {
}

void mine(@Observes StartupEvent event) {
logger.atInfo().log("Start mining with spoon");
vertx.setTimer(TimeUnit.MINUTES.toMillis(5), v -> vertx.executeBlocking(it -> mineRandomRepo()));
}

private void mineRandomRepo() {
try {
logger.atInfo().log("Start mining with spoon");
var project = queue.isEmpty() ? getRandomProject() : queue.poll();
var checkoutResult = checkoutProject(project);
if (checkoutResult instanceof ProjectResult.Error) {
logger.atWarning().log("Failed to checkout project %s", project);
mineRandomRepo();
return;
}

if (checkoutResult instanceof ProjectResult.Success success) {
String commitHash = success.project().commitHash();
if (isAlreadyMined(success, commitHash, ANALYZER_NAME)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.flogger.FluentLogger;
import com.mongodb.client.model.Filters;
import com.mongodb.client.result.DeleteResult;
import io.github.martinwitt.laughing_train.domain.entity.Project;
import io.github.martinwitt.laughing_train.domain.entity.ProjectConfig;
import io.github.martinwitt.laughing_train.persistence.impl.MongoBadSmellRepository;
Expand Down Expand Up @@ -68,7 +67,6 @@ private void migrateDataBase(Promise<Object> promise) {
removeProjectHashesWithoutResults();
removeProjectsWithOutHashes();
removeDuplicatedProjects();
removeBadSmellsFromSpoon();
logger.atInfo().log("Finished migrating database");
promise.complete();
}
Expand Down Expand Up @@ -122,12 +120,4 @@ private void removeDuplicatedProjects() {
.forEach(project -> projectRepository.deleteByProjectUrl(project.getProjectUrl()));
logger.atInfo().log("Finished removing duplicated projects");
}

private void removeBadSmellsFromSpoon() {
logger.atInfo().log("Removing bad smells from spoon");
DeleteResult deleteMany =
badSmellRepositoryImpl.mongoCollection().deleteMany(Filters.eq("analyzer", "SpoonAnalyzer"));
;
logger.atInfo().log("Finished removing bad smells from spoon" + deleteMany);
}
}

0 comments on commit 7431304

Please sign in to comment.