(process) Ensure construction exceptions are logged

Wrapping these exceptions in a try-catch and logging them with slf4j will ensure they end up in the process logs.

The way it worked using the default exception handler, they'd print on console (which nothing captures!), leading to a very annoying debugging experience.
This commit is contained in:
Viktor Lofgren 2023-11-22 18:31:27 +01:00
parent dd507a3808
commit 09917837d0
4 changed files with 63 additions and 48 deletions

View File

@ -50,21 +50,27 @@ public class ConverterMain {
private final int node;
public static void main(String... args) throws Exception {
Injector injector = Guice.createInjector(
new ConverterModule(),
new ProcessConfigurationModule("converter"),
new DatabaseModule()
);
var converter = injector.getInstance(ConverterMain.class);
try {
Injector injector = Guice.createInjector(
new ConverterModule(),
new ProcessConfigurationModule("converter"),
new DatabaseModule()
);
logger.info("Starting pipe");
var converter = injector.getInstance(ConverterMain.class);
converter
.fetchInstructions()
.execute(converter);
logger.info("Starting pipe");
logger.info("Finished");
converter
.fetchInstructions()
.execute(converter);
logger.info("Finished");
}
catch (Exception ex) {
logger.error("Uncaught Exception", ex);
}
System.exit(0);
}

View File

@ -46,7 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static nu.marginalia.mqapi.ProcessInboxNames.CRAWLER_INBOX;
public class CrawlerMain {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final static Logger logger = LoggerFactory.getLogger(CrawlerMain.class);
private final ProcessHeartbeatImpl heartbeat;
private final ConnectionPool connectionPool = new ConnectionPool(5, 10, TimeUnit.SECONDS);
@ -110,26 +110,28 @@ public class CrawlerMain {
// We don't want to use too much memory caching sessions for https
System.setProperty("javax.net.ssl.sessionCacheSize", "2048");
Injector injector = Guice.createInjector(
new CrawlerModule(),
new ProcessConfigurationModule("crawler"),
new DatabaseModule()
);
var crawler = injector.getInstance(CrawlerMain.class);
var instructions = crawler.fetchInstructions();
try {
crawler.run(instructions.specProvider, instructions.outputDir);
instructions.ok();
Injector injector = Guice.createInjector(
new CrawlerModule(),
new ProcessConfigurationModule("crawler"),
new DatabaseModule()
);
var crawler = injector.getInstance(CrawlerMain.class);
var instructions = crawler.fetchInstructions();
try {
crawler.run(instructions.specProvider, instructions.outputDir);
instructions.ok();
} catch (Exception ex) {
logger.error("Crawler failed", ex);
instructions.err();
}
TimeUnit.SECONDS.sleep(5);
}
catch (Exception ex) {
System.err.println("Crawler failed");
ex.printStackTrace();
instructions.err();
logger.error("Uncaught exception", ex);
}
TimeUnit.SECONDS.sleep(5);
System.exit(0);
}

View File

@ -48,25 +48,31 @@ public class IndexConstructorMain {
private static final Logger logger = LoggerFactory.getLogger(IndexConstructorMain.class);
private final Gson gson = GsonFactory.get();
public static void main(String[] args) throws Exception {
new org.mariadb.jdbc.Driver();
var main = Guice.createInjector(
new IndexConstructorModule(),
new ProcessConfigurationModule("index-constructor"),
new DatabaseModule())
.getInstance(IndexConstructorMain.class);
var instructions = main.fetchInstructions();
CreateIndexInstructions instructions = null;
try {
new org.mariadb.jdbc.Driver();
var main = Guice.createInjector(
new IndexConstructorModule(),
new ProcessConfigurationModule("index-constructor"),
new DatabaseModule())
.getInstance(IndexConstructorMain.class);
instructions = main.fetchInstructions();
main.run(instructions);
instructions.ok();
}
catch (Exception ex) {
logger.error("Constructor failed", ex);
instructions.err();
if (instructions != null) {
instructions.err();
}
}
// Grace period so we don't rug pull the logger or jdbc
TimeUnit.SECONDS.sleep(5);
System.exit(0);

View File

@ -52,17 +52,18 @@ public class LoaderMain {
private final int node;
private final Gson gson;
public static void main(String... args) throws Exception {
new org.mariadb.jdbc.Driver();
Injector injector = Guice.createInjector(
new ProcessConfigurationModule("loader"),
new LoaderModule(),
new DatabaseModule()
);
var instance = injector.getInstance(LoaderMain.class);
public static void main(String... args) {
try {
new org.mariadb.jdbc.Driver();
Injector injector = Guice.createInjector(
new ProcessConfigurationModule("loader"),
new LoaderModule(),
new DatabaseModule()
);
var instance = injector.getInstance(LoaderMain.class);
var instructions = instance.fetchInstructions();
logger.info("Instructions received");
instance.run(instructions);