Skip to content

Commit

Permalink
Explicitly stop and start managed dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-signal authored Oct 24, 2023
1 parent 325d145 commit 3d92e5b
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,31 @@ protected void run(final Environment environment, final Namespace namespace,

final int segments = Objects.requireNonNull(namespace.getInt(SEGMENT_COUNT));

environment.lifecycle().manage(new CommandStopListener(configuration.getCommandStopListener()));

logger.info("Crawling accounts with {} segments and {} processors",
segments,
Runtime.getRuntime().availableProcessors());

final CommandStopListener commandStopListener = new CommandStopListener(configuration.getCommandStopListener());
try {
commandStopListener.start();
environment.lifecycle().getManagedObjects().forEach(managedObject -> {
try {
managedObject.start();
} catch (final Exception e) {
logger.error("Failed to start managed object", e);
throw new RuntimeException(e);
}
});

crawlAccounts(commandDependencies.accountsManager().streamAllFromDynamo(segments, Schedulers.parallel()));
} finally {
commandStopListener.stop();
environment.lifecycle().getManagedObjects().forEach(managedObject -> {
try {
managedObject.stop();
} catch (final Exception e) {
logger.error("Failed to stop managed object", e);
}
});
}
}

Expand Down

0 comments on commit 3d92e5b

Please sign in to comment.