use of net.robinfriedli.aiode.command.Command in project aiode by robinfriedli.
the class CleanDbCommand method runAdmin.
@Override
public void runAdmin() {
Aiode.shutdownListeners();
try {
if (!argumentSet("silent")) {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle("Scheduled cleanup");
embedBuilder.setDescription("Aiode is suspending for a few seconds to clean the database.");
sendToActiveGuilds(embedBuilder.build());
}
CommandExecutionQueueManager executionQueueManager = Aiode.get().getExecutionQueueManager();
Command command = this;
Thread cleanupThread = new Thread(() -> {
ThreadContext.Current.install(command);
try {
try {
executionQueueManager.joinAll(60000);
} catch (InterruptedException e) {
return;
}
StaticSessionProvider.consumeSession(this::doClean);
} finally {
Aiode.registerListeners();
}
});
cleanupThread.setName("database-cleanup-thread-" + command.getContext().toString());
Thread.UncaughtExceptionHandler commandExecutionExceptionHandler = Thread.currentThread().getUncaughtExceptionHandler();
if (commandExecutionExceptionHandler != null) {
cleanupThread.setUncaughtExceptionHandler(commandExecutionExceptionHandler);
}
cleanupThread.start();
} catch (Throwable e) {
Aiode.registerListeners();
throw e;
}
}
use of net.robinfriedli.aiode.command.Command in project aiode by robinfriedli.
the class CommandUncaughtExceptionHandler method uncaughtException.
@Override
public void uncaughtException(Thread t, Throwable e) {
Command command = ThreadContext.Current.get(Command.class);
if (command != null) {
try {
ExceptionUtils.handleCommandException(e, command, logger);
return;
} catch (Exception e1) {
logger.error("Exception while calling ExceptionUtils#handleCommandException, falling back to logging error", e1);
}
}
logger.error("Exception in command handler thread", e);
}
Aggregations