mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00

Since some of the export tasks have been memory hungry, sometimes killing the executor-services, they've been moved to a separate process that can be given a larger Xmx. While doing this, the ProcessMainClass was given utilities for the boilerplate surrounding receiving mq requests and responding to them, some effort was also put toward making the process boot process a bit more uniform. It's still a bit heterogeneous between different processes, but a bit less so for now.
43 lines
1.3 KiB
Java
43 lines
1.3 KiB
Java
package nu.marginalia.process;
|
|
|
|
import com.google.inject.AbstractModule;
|
|
import com.google.inject.name.Names;
|
|
|
|
import java.util.UUID;
|
|
|
|
public class ProcessConfigurationModule extends AbstractModule {
|
|
private final String processName;
|
|
|
|
public ProcessConfigurationModule(String processName) {
|
|
this.processName = processName;
|
|
}
|
|
|
|
public void configure() {
|
|
bind(Integer.class).annotatedWith(Names.named("wmsa-system-node")).toInstance(getNode());
|
|
bind(ProcessConfiguration.class).toInstance(new ProcessConfiguration(processName, getNode(), UUID.randomUUID()));
|
|
}
|
|
|
|
private int getNode() {
|
|
|
|
String nodeEnv = System.getenv("WMSA_PROCESS_NODE");
|
|
|
|
if (null == nodeEnv) {
|
|
// fallback logic, try to inherit from parent via environment variable
|
|
nodeEnv = System.getenv("WMSA_SERVICE_NODE");
|
|
}
|
|
|
|
if (null == nodeEnv) {
|
|
// fallback logic, try to inherit from parent via system property
|
|
nodeEnv = System.getProperty("system.serviceNode");
|
|
}
|
|
|
|
//
|
|
if (null == nodeEnv) {
|
|
throw new IllegalStateException("Either WMSA_PROCESS_NODE or WMSA_SERVICE_NODE must be set, indicating the node affinity of the process!");
|
|
}
|
|
|
|
return Integer.parseInt(nodeEnv);
|
|
}
|
|
|
|
}
|