Skip to content

Commit

Permalink
feat: ✨ Separated Qodana and Spoon mining (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Jun 10, 2023
1 parent dc67fd7 commit dda44b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand All @@ -106,28 +139,16 @@ 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");
registry.counter("mining.error").increment();
} 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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit dda44b2

Please sign in to comment.