mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-02-21 00:17:05 +01:00
[Feature] Set Executor Instances limits dynamically from properties (#2193)
* Update 'ProcessExecutor.java' to use dynamic process limits from properties * Move limits location out of 'application.properties' * Rename 'SemaphoreLimit' to 'SessionLimit' and bundle with 'Timeout...' into one parent class
This commit is contained in:
parent
c921b5d76f
commit
7eea7fb3cb
@ -47,6 +47,7 @@ public class ApplicationProperties {
|
|||||||
private AutomaticallyGenerated automaticallyGenerated = new AutomaticallyGenerated();
|
private AutomaticallyGenerated automaticallyGenerated = new AutomaticallyGenerated();
|
||||||
private EnterpriseEdition enterpriseEdition = new EnterpriseEdition();
|
private EnterpriseEdition enterpriseEdition = new EnterpriseEdition();
|
||||||
private AutoPipeline autoPipeline = new AutoPipeline();
|
private AutoPipeline autoPipeline = new AutoPipeline();
|
||||||
|
private ProcessExecutor processExecutor = new ProcessExecutor();
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class AutoPipeline {
|
public static class AutoPipeline {
|
||||||
@ -309,4 +310,98 @@ public class ApplicationProperties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class ProcessExecutor {
|
||||||
|
private SessionLimit sessionLimit = new SessionLimit();
|
||||||
|
private TimeoutMinutes timeoutMinutes = new TimeoutMinutes();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class SessionLimit {
|
||||||
|
private int libreOfficeSessionLimit;
|
||||||
|
private int pdfToHtmlSessionLimit;
|
||||||
|
private int ocrMyPdfSessionLimit;
|
||||||
|
private int pythonOpenCvSessionLimit;
|
||||||
|
private int ghostScriptSessionLimit;
|
||||||
|
private int weasyPrintSessionLimit;
|
||||||
|
private int installAppSessionLimit;
|
||||||
|
private int calibreSessionLimit;
|
||||||
|
|
||||||
|
public int getLibreOfficeSessionLimit() {
|
||||||
|
return libreOfficeSessionLimit > 0 ? libreOfficeSessionLimit : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPdfToHtmlSessionLimit() {
|
||||||
|
return pdfToHtmlSessionLimit > 0 ? pdfToHtmlSessionLimit : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOcrMyPdfSessionLimit() {
|
||||||
|
return ocrMyPdfSessionLimit > 0 ? ocrMyPdfSessionLimit : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPythonOpenCvSessionLimit() {
|
||||||
|
return pythonOpenCvSessionLimit > 0 ? pythonOpenCvSessionLimit : 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGhostScriptSessionLimit() {
|
||||||
|
return ghostScriptSessionLimit > 0 ? ghostScriptSessionLimit : 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWeasyPrintSessionLimit() {
|
||||||
|
return weasyPrintSessionLimit > 0 ? weasyPrintSessionLimit : 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInstallAppSessionLimit() {
|
||||||
|
return installAppSessionLimit > 0 ? installAppSessionLimit : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCalibreSessionLimit() {
|
||||||
|
return calibreSessionLimit > 0 ? calibreSessionLimit : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class TimeoutMinutes {
|
||||||
|
private long libreOfficeTimeoutMinutes;
|
||||||
|
private long pdfToHtmlTimeoutMinutes;
|
||||||
|
private long ocrMyPdfTimeoutMinutes;
|
||||||
|
private long pythonOpenCvTimeoutMinutes;
|
||||||
|
private long ghostScriptTimeoutMinutes;
|
||||||
|
private long weasyPrintTimeoutMinutes;
|
||||||
|
private long installAppTimeoutMinutes;
|
||||||
|
private long calibreTimeoutMinutes;
|
||||||
|
|
||||||
|
public long getLibreOfficeTimeoutMinutes() {
|
||||||
|
return libreOfficeTimeoutMinutes > 0 ? libreOfficeTimeoutMinutes : 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPdfToHtmlTimeoutMinutes() {
|
||||||
|
return pdfToHtmlTimeoutMinutes > 0 ? pdfToHtmlTimeoutMinutes : 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getOcrMyPdfTimeoutMinutes() {
|
||||||
|
return ocrMyPdfTimeoutMinutes > 0 ? ocrMyPdfTimeoutMinutes : 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPythonOpenCvTimeoutMinutes() {
|
||||||
|
return pythonOpenCvTimeoutMinutes > 0 ? pythonOpenCvTimeoutMinutes : 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getGhostScriptTimeoutMinutes() {
|
||||||
|
return ghostScriptTimeoutMinutes > 0 ? ghostScriptTimeoutMinutes : 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getWeasyPrintTimeoutMinutes() {
|
||||||
|
return weasyPrintTimeoutMinutes > 0 ? weasyPrintTimeoutMinutes : 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getInstallAppTimeoutMinutes() {
|
||||||
|
return installAppTimeoutMinutes > 0 ? installAppTimeoutMinutes : 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCalibreTimeoutMinutes() {
|
||||||
|
return calibreTimeoutMinutes > 0 ? calibreTimeoutMinutes : 30;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,14 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import io.github.pixee.security.BoundedLineReader;
|
import io.github.pixee.security.BoundedLineReader;
|
||||||
|
|
||||||
|
import stirling.software.SPDF.model.ApplicationProperties;
|
||||||
|
|
||||||
public class ProcessExecutor {
|
public class ProcessExecutor {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ProcessExecutor.class);
|
private static final Logger logger = LoggerFactory.getLogger(ProcessExecutor.class);
|
||||||
|
|
||||||
|
private static ApplicationProperties applicationProperties = new ApplicationProperties();
|
||||||
|
|
||||||
public enum Processes {
|
public enum Processes {
|
||||||
LIBRE_OFFICE,
|
LIBRE_OFFICE,
|
||||||
PDFTOHTML,
|
PDFTOHTML,
|
||||||
@ -45,26 +49,90 @@ public class ProcessExecutor {
|
|||||||
key -> {
|
key -> {
|
||||||
int semaphoreLimit =
|
int semaphoreLimit =
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case LIBRE_OFFICE -> 1;
|
case LIBRE_OFFICE ->
|
||||||
case PDFTOHTML -> 1;
|
applicationProperties
|
||||||
case OCR_MY_PDF -> 2;
|
.getProcessExecutor()
|
||||||
case PYTHON_OPENCV -> 8;
|
.getSessionLimit()
|
||||||
case GHOSTSCRIPT -> 16;
|
.getLibreOfficeSessionLimit();
|
||||||
case WEASYPRINT -> 16;
|
case PDFTOHTML ->
|
||||||
case INSTALL_APP -> 1;
|
applicationProperties
|
||||||
case CALIBRE -> 1;
|
.getProcessExecutor()
|
||||||
|
.getSessionLimit()
|
||||||
|
.getPdfToHtmlSessionLimit();
|
||||||
|
case OCR_MY_PDF ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getSessionLimit()
|
||||||
|
.getOcrMyPdfSessionLimit();
|
||||||
|
case PYTHON_OPENCV ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getSessionLimit()
|
||||||
|
.getPythonOpenCvSessionLimit();
|
||||||
|
case GHOSTSCRIPT ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getSessionLimit()
|
||||||
|
.getGhostScriptSessionLimit();
|
||||||
|
case WEASYPRINT ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getSessionLimit()
|
||||||
|
.getWeasyPrintSessionLimit();
|
||||||
|
case INSTALL_APP ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getSessionLimit()
|
||||||
|
.getInstallAppSessionLimit();
|
||||||
|
case CALIBRE ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getSessionLimit()
|
||||||
|
.getCalibreSessionLimit();
|
||||||
};
|
};
|
||||||
|
|
||||||
long timeoutMinutes =
|
long timeoutMinutes =
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case LIBRE_OFFICE -> 30;
|
case LIBRE_OFFICE ->
|
||||||
case PDFTOHTML -> 20;
|
applicationProperties
|
||||||
case OCR_MY_PDF -> 30;
|
.getProcessExecutor()
|
||||||
case PYTHON_OPENCV -> 30;
|
.getTimeoutMinutes()
|
||||||
case GHOSTSCRIPT -> 30;
|
.getLibreOfficeTimeoutMinutes();
|
||||||
case WEASYPRINT -> 30;
|
case PDFTOHTML ->
|
||||||
case INSTALL_APP -> 60;
|
applicationProperties
|
||||||
case CALIBRE -> 30;
|
.getProcessExecutor()
|
||||||
|
.getTimeoutMinutes()
|
||||||
|
.getPdfToHtmlTimeoutMinutes();
|
||||||
|
case OCR_MY_PDF ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getTimeoutMinutes()
|
||||||
|
.getOcrMyPdfTimeoutMinutes();
|
||||||
|
case PYTHON_OPENCV ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getTimeoutMinutes()
|
||||||
|
.getPythonOpenCvTimeoutMinutes();
|
||||||
|
case GHOSTSCRIPT ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getTimeoutMinutes()
|
||||||
|
.getGhostScriptTimeoutMinutes();
|
||||||
|
case WEASYPRINT ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getTimeoutMinutes()
|
||||||
|
.getWeasyPrintTimeoutMinutes();
|
||||||
|
case INSTALL_APP ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getTimeoutMinutes()
|
||||||
|
.getInstallAppTimeoutMinutes();
|
||||||
|
case CALIBRE ->
|
||||||
|
applicationProperties
|
||||||
|
.getProcessExecutor()
|
||||||
|
.getTimeoutMinutes()
|
||||||
|
.getCalibreTimeoutMinutes();
|
||||||
};
|
};
|
||||||
return new ProcessExecutor(semaphoreLimit, liveUpdates, timeoutMinutes);
|
return new ProcessExecutor(semaphoreLimit, liveUpdates, timeoutMinutes);
|
||||||
});
|
});
|
||||||
|
@ -50,4 +50,4 @@ springdoc.swagger-ui.url=/v1/api-docs
|
|||||||
|
|
||||||
|
|
||||||
posthog.api.key=phc_fiR65u5j6qmXTYL56MNrLZSWqLaDW74OrZH0Insd2xq
|
posthog.api.key=phc_fiR65u5j6qmXTYL56MNrLZSWqLaDW74OrZH0Insd2xq
|
||||||
posthog.host=https://eu.i.posthog.com
|
posthog.host=https://eu.i.posthog.com
|
||||||
|
@ -102,3 +102,22 @@ metrics:
|
|||||||
AutomaticallyGenerated:
|
AutomaticallyGenerated:
|
||||||
key: example
|
key: example
|
||||||
UUID: example
|
UUID: example
|
||||||
|
|
||||||
|
processExecutor:
|
||||||
|
sessionLimit: # Process executor instances limits
|
||||||
|
libreOfficeSessionLimit: 1
|
||||||
|
pdfToHtmlSessionLimit: 1
|
||||||
|
ocrMyPdfSessionLimit: 2
|
||||||
|
pythonOpenCvSessionLimit: 8
|
||||||
|
ghostScriptSessionLimit: 16
|
||||||
|
weasyPrintSessionLimit: 16
|
||||||
|
installAppSessionLimit: 1
|
||||||
|
calibreSessionLimit: 1
|
||||||
|
timeoutMinutes: # Process executor timeout in minutes
|
||||||
|
libreOfficetimeoutMinutes: 30
|
||||||
|
pdfToHtmltimeoutMinutes: 20
|
||||||
|
pythonOpenCvtimeoutMinutes: 30
|
||||||
|
ghostScripttimeoutMinutes: 30
|
||||||
|
weasyPrinttimeoutMinutes: 30
|
||||||
|
installApptimeoutMinutes: 60
|
||||||
|
calibretimeoutMinutes: 30
|
||||||
|
Loading…
Reference in New Issue
Block a user