0
0
mirror of https://github.com/signalapp/Signal-Server.git synced 2024-09-20 03:52:16 +02:00

Explicitly stop and start managed dependencies

This commit is contained in:
Jon Chambers 2023-10-24 16:50:02 -04:00 committed by GitHub
parent 325d145ac3
commit 3d92e5b8a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,16 +70,31 @@ public abstract class AbstractSinglePassCrawlAccountsCommand extends Environment
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);
}
});
}
}