(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,6 +50,8 @@ public class ConverterMain {
private final int node;
public static void main(String... args) throws Exception {
try {
Injector injector = Guice.createInjector(
new ConverterModule(),
new ProcessConfigurationModule("converter"),
@ -65,6 +67,10 @@ public class ConverterMain {
.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,6 +110,7 @@ public class CrawlerMain {
// We don't want to use too much memory caching sessions for https
System.setProperty("javax.net.ssl.sessionCacheSize", "2048");
try {
Injector injector = Guice.createInjector(
new CrawlerModule(),
new ProcessConfigurationModule("crawler"),
@ -121,15 +122,16 @@ public class CrawlerMain {
try {
crawler.run(instructions.specProvider, instructions.outputDir);
instructions.ok();
}
catch (Exception ex) {
System.err.println("Crawler failed");
ex.printStackTrace();
} catch (Exception ex) {
logger.error("Crawler failed", ex);
instructions.err();
}
TimeUnit.SECONDS.sleep(5);
}
catch (Exception ex) {
logger.error("Uncaught exception", ex);
}
System.exit(0);
}

View File

@ -48,6 +48,9 @@ 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 {
CreateIndexInstructions instructions = null;
try {
new org.mariadb.jdbc.Driver();
var main = Guice.createInjector(
@ -56,17 +59,20 @@ public class IndexConstructorMain {
new DatabaseModule())
.getInstance(IndexConstructorMain.class);
var instructions = main.fetchInstructions();
instructions = main.fetchInstructions();
try {
main.run(instructions);
instructions.ok();
}
catch (Exception ex) {
logger.error("Constructor failed", ex);
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,7 +52,8 @@ public class LoaderMain {
private final int node;
private final Gson gson;
public static void main(String... args) throws Exception {
public static void main(String... args) {
try {
new org.mariadb.jdbc.Driver();
Injector injector = Guice.createInjector(
@ -62,7 +63,7 @@ public class LoaderMain {
);
var instance = injector.getInstance(LoaderMain.class);
try {
var instructions = instance.fetchInstructions();
logger.info("Instructions received");
instance.run(instructions);