Skip to content

Commit

Permalink
fix(vertx): Wait with mining till all verticles are deployed (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Jul 13, 2023
1 parent 297cf25 commit 1a4ba5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.github.martinwitt.laughing_train.mining;

import io.github.martinwitt.laughing_train.mining.requests.MineNextProject;
import io.quarkus.logging.Log;
import io.quarkus.runtime.StartupEvent;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
Expand All @@ -29,14 +31,22 @@ public class MiningStartup {

void startup(@Observes StartupEvent event) {
DeploymentOptions options = new DeploymentOptions().setWorker(true);
vertx.deployVerticle(qodanaPeriodicMiner, options);
vertx.deployVerticle(spoonPeriodicMiner, options);
vertx.deployVerticle(persistence, options);
vertx.deployVerticle(projectSupplier, options);
Future.join(
vertx.deployVerticle(qodanaPeriodicMiner, options),
vertx.deployVerticle(spoonPeriodicMiner, options),
vertx.deployVerticle(persistence, options),
vertx.deployVerticle(projectSupplier, options))
.onFailure(Throwable::printStackTrace)
.onComplete(v -> System.out.println("All verticles deployed"))
.onSuccess(v -> startPeriodicMining());
vertx.eventBus().addInboundInterceptor(v -> {
System.out.println("Received message: " + v.toString());
v.next();
});
}

private void startPeriodicMining() {
Log.info("Starting periodic mining");
vertx.setPeriodic(TimeUnit.MINUTES.toMillis(3), TimeUnit.MINUTES.toMillis(25), v -> vertx.eventBus()
.publish("miner", new MineNextProject(QodanaPeriodicMiner.ANALYZER_NAME)));
vertx.setPeriodic(TimeUnit.MINUTES.toMillis(2), TimeUnit.MINUTES.toMillis(15), v -> vertx.eventBus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
public class ProjectSupplier extends AbstractVerticle {

public static final String SERVICE_NAME = "projectSupplier";

private static final Random random = new Random();
final SearchProjectService searchProjectService;
final ProjectRepository projectRepository;
final ProjectService projectService;
final Vertx vertx;
final Random random;

@Produces
Random random() {
Expand All @@ -35,13 +34,11 @@ Random random() {
SearchProjectService searchProjectService,
ProjectRepository projectRepository,
ProjectService projectService,
Vertx vertx,
Random random) {
Vertx vertx) {
this.searchProjectService = searchProjectService;
this.projectRepository = projectRepository;
this.projectService = projectService;
this.vertx = vertx;
this.random = random;
}

@Override
Expand Down

0 comments on commit 1a4ba5b

Please sign in to comment.