From 464bef94f4d90e68a453ad1bc2f7c45894cc2e7c Mon Sep 17 00:00:00 2001 From: Martin Wittlinger Date: Sat, 10 Jun 2023 14:37:12 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Separated=20Qodana=20and=20?= =?UTF-8?q?Spoon=20mining?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../laughing_train/mining/PeriodicMiner.java | 53 +++++++++++++------ .../api/BadSmellGraphQLTest.java | 1 - 2 files changed, 37 insertions(+), 17 deletions(-) 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 8343f2e72..972aae855 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 @@ -81,21 +81,54 @@ private Project getKnownProject() { } void mine(@Observes StartupEvent event) { - vertx.setTimer(TimeUnit.MINUTES.toMillis(5), v -> vertx.executeBlocking(it -> mineRandomRepo())); + vertx.setTimer(TimeUnit.MINUTES.toMillis(5), v -> vertx.executeBlocking(it -> mineRandomRepoQodana())); + vertx.setTimer(TimeUnit.MINUTES.toMillis(5), v -> vertx.executeBlocking(it -> mineRandomRepoSpoon())); } - private void mineRandomRepo() { + private void mineRandomRepoQodana() { try { 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(); + mineRandomRepoQodana(); return; } if (checkoutResult instanceof ProjectResult.Success success) { logger.atInfo().log("Successfully checked out project %s", success.project()); var qodanaResult = analyzeProject(success); + + if (qodanaResult instanceof QodanaResult.Failure failure) { + logger.atWarning().log("Failed to analyze project %s", failure.message()); + tryDeleteProject(success); + return; + } + if (qodanaResult instanceof QodanaResult.Success successResult) { + logger.atInfo().log("Successfully analyzed project %s", success.project()); + saveQodanaResults(successResult); + addOrUpdateCommitHash(success); + } + } + } catch (Exception e) { + logger.atWarning().withCause(e).log("Failed to mine random repo"); + } finally { + logger.atInfo().log("Queue size: %s", queue.size()); + logger.atInfo().log("Mining next repo in 1 minute"); + vertx.setTimer(TimeUnit.MINUTES.toMillis(1), v -> vertx.executeBlocking(it -> mineRandomRepoQodana())); + } + } + + private void mineRandomRepoSpoon() { + try { + 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); + mineRandomRepoSpoon(); + return; + } + if (checkoutResult instanceof ProjectResult.Success success) { + logger.atInfo().log("Successfully checked out project %s", success.project()); var spoonPatternAnalyzerResult = spoonPatternAnalyzer.analyze(new AnalyzerRequest.WithProject(success.project())); @@ -106,20 +139,8 @@ private void mineRandomRepo() { } if (spoonPatternAnalyzerResult instanceof SpoonPatternAnalyzerResult.Failure failure) { logger.atWarning().log("Failed to analyze project with spoon %s", failure.message()); - registry.counter("mining.spoon.error").increment(); tryDeleteProject(success); } - if (qodanaResult instanceof QodanaResult.Failure failure) { - logger.atWarning().log("Failed to analyze project %s", failure.message()); - registry.counter("mining.qodana.error").increment(); - tryDeleteProject(success); - return; - } - if (qodanaResult instanceof QodanaResult.Success successResult) { - logger.atInfo().log("Successfully analyzed project %s", success.project()); - saveQodanaResults(successResult); - addOrUpdateCommitHash(success); - } } } catch (Exception e) { logger.atWarning().withCause(e).log("Failed to mine random repo"); @@ -127,7 +148,7 @@ private void mineRandomRepo() { } finally { logger.atInfo().log("Queue size: %s", queue.size()); logger.atInfo().log("Mining next repo in 1 minute"); - vertx.setTimer(TimeUnit.MINUTES.toMillis(1), v -> vertx.executeBlocking(it -> mineRandomRepo())); + vertx.setTimer(TimeUnit.MINUTES.toMillis(1), v -> vertx.executeBlocking(it -> mineRandomRepoSpoon())); } } diff --git a/github-bot/src/test/java/io/github/martinwitt/laughing_train/api/BadSmellGraphQLTest.java b/github-bot/src/test/java/io/github/martinwitt/laughing_train/api/BadSmellGraphQLTest.java index c0ecf51c3..c2563758f 100644 --- a/github-bot/src/test/java/io/github/martinwitt/laughing_train/api/BadSmellGraphQLTest.java +++ b/github-bot/src/test/java/io/github/martinwitt/laughing_train/api/BadSmellGraphQLTest.java @@ -21,7 +21,6 @@ import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClientBuilder; import jakarta.inject.Inject; import java.util.regex.Pattern; - import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test;