Skip to content

Commit

Permalink
fix(vertx): Use reply instead of return (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Jul 13, 2023
1 parent 3eb5c6e commit 297cf25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions github-bot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation project(":application")
implementation project(":commons")
implementation "io.quarkiverse.loggingmanager:quarkus-logging-manager:3.0.0"
testImplementation 'org.mockito:mockito-core:5.4.0'
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import io.github.martinwitt.laughing_train.mining.requests.GetProject;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.github.martinwitt.laughing_train.services.ProjectService;
import io.quarkus.logging.Log;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.Message;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import java.io.IOException;
import java.util.Random;

Expand All @@ -20,31 +23,40 @@ public class ProjectSupplier extends AbstractVerticle {
final SearchProjectService searchProjectService;
final ProjectRepository projectRepository;
final ProjectService projectService;
private static final Random random = new Random();
final Vertx vertx;
final Random random;

@Produces
Random random() {
return new Random();
}

ProjectSupplier(
SearchProjectService searchProjectService,
ProjectRepository projectRepository,
ProjectService projectService,
Vertx vertx) {
Vertx vertx,
Random random) {
this.searchProjectService = searchProjectService;
this.projectRepository = projectRepository;
this.projectService = projectService;
this.vertx = vertx;
this.random = random;
}

@Override
public void start() throws Exception {
vertx.eventBus().<GetProject>consumer(SERVICE_NAME, v -> supplyProject(v.body()));
vertx.eventBus().<GetProject>consumer(SERVICE_NAME, v -> supplyProject(v));
}

ProjectResult supplyProject(GetProject getProject) {
void supplyProject(Message<GetProject> getProject) {
try {
Project project = getRandomProject();
return checkoutProject(project);
ProjectResult checkoutProject = checkoutProject(project);
Log.info("Project %s checked out".formatted(project.getProjectUrl()));
getProject.reply(checkoutProject);
} catch (IOException e) {
return new ProjectResult.Error(e.getMessage());
getProject.reply(new ProjectResult.Error(e.getMessage()));
}
}

Expand Down

0 comments on commit 297cf25

Please sign in to comment.