mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
Fixing scheduled process context; better thread names; add serverInfo endpoint
This commit is contained in:
@ -58,7 +58,6 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.automation.QTableAut
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.automation.TableAutomationAction;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.automation.TriggerEvent;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
import com.kingsrook.qqq.backend.core.scheduler.StandardScheduledExecutor;
|
||||
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
|
||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
@ -178,7 +177,7 @@ public class PollingAutomationPerTableRunner implements Runnable
|
||||
QContext.init(instance, sessionSupplier.get());
|
||||
|
||||
String originalThreadName = Thread.currentThread().getName();
|
||||
Thread.currentThread().setName(name + StandardScheduledExecutor.newThreadNameRandomSuffix());
|
||||
Thread.currentThread().setName(name);
|
||||
LOG.info("Running " + this.getClass().getSimpleName() + "[" + name + "]");
|
||||
|
||||
try
|
||||
|
@ -43,7 +43,6 @@ import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.queues.QQueueMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.metadata.queues.SQSQueueProviderMetaData;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
import com.kingsrook.qqq.backend.core.scheduler.StandardScheduledExecutor;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -73,7 +72,7 @@ public class SQSQueuePoller implements Runnable
|
||||
QContext.init(qInstance, sessionSupplier.get());
|
||||
|
||||
String originalThreadName = Thread.currentThread().getName();
|
||||
Thread.currentThread().setName("SQSPoller>" + queueMetaData.getName() + StandardScheduledExecutor.newThreadNameRandomSuffix());
|
||||
Thread.currentThread().setName("SQSPoller>" + queueMetaData.getName());
|
||||
LOG.debug("Running " + this.getClass().getSimpleName() + "[" + queueMetaData.getName() + "]");
|
||||
|
||||
try
|
||||
|
@ -29,7 +29,6 @@ import java.util.function.Supplier;
|
||||
import com.kingsrook.qqq.backend.core.actions.automation.polling.PollingAutomationPerTableRunner;
|
||||
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.queues.SQSQueuePoller;
|
||||
import com.kingsrook.qqq.backend.core.context.CapturedContext;
|
||||
import com.kingsrook.qqq.backend.core.context.QContext;
|
||||
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
|
||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||
@ -105,16 +104,16 @@ public class ScheduleManager
|
||||
String propertyValue = System.getProperty(propertyName);
|
||||
if("false".equals(propertyValue))
|
||||
{
|
||||
LOG.warn("Not starting ScheduleManager (per system property] [" + propertyName + "=" + propertyValue + "]).");
|
||||
LOG.info("Not starting ScheduleManager (per system property] [" + propertyName + "=" + propertyValue + "]).");
|
||||
return;
|
||||
}
|
||||
|
||||
QMetaDataVariableInterpreter qMetaDataVariableInterpreter = new QMetaDataVariableInterpreter();
|
||||
String envName = "QQQ_SCHEDULE_MANAGER_ENABLED";
|
||||
String envValue = qMetaDataVariableInterpreter.interpret("${env." + envName + "}");
|
||||
String envName = "QQQ_SCHEDULE_MANAGER_ENABLED";
|
||||
String envValue = qMetaDataVariableInterpreter.interpret("${env." + envName + "}");
|
||||
if("false".equals(envValue))
|
||||
{
|
||||
LOG.warn("Not starting ScheduleManager (per environment variable] [" + envName + "=" + envValue + "]).");
|
||||
LOG.info("Not starting ScheduleManager (per environment variable] [" + envName + "=" + envValue + "]).");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -252,17 +251,16 @@ public class ScheduleManager
|
||||
*******************************************************************************/
|
||||
private void startProcess(QProcessMetaData process)
|
||||
{
|
||||
CapturedContext capturedContext = QContext.capture();
|
||||
|
||||
Runnable runProcess = () ->
|
||||
{
|
||||
QContext.init(capturedContext);
|
||||
String originalThreadName = Thread.currentThread().getName();
|
||||
Thread.currentThread().setName("ScheduledProcess>" + process.getName() + StandardScheduledExecutor.newThreadNameRandomSuffix());
|
||||
LOG.debug("Running Scheduled Process [" + process.getName() + "]");
|
||||
|
||||
try
|
||||
{
|
||||
QContext.init(qInstance, sessionSupplier.get());
|
||||
Thread.currentThread().setName("ScheduledProcess>" + process.getName());
|
||||
LOG.debug("Running Scheduled Process [" + process.getName() + "]");
|
||||
|
||||
RunProcessInput runProcessInput = new RunProcessInput();
|
||||
runProcessInput.setProcessName(process.getName());
|
||||
runProcessInput.setFrontendStepBehavior(RunProcessInput.FrontendStepBehavior.SKIP);
|
||||
|
@ -22,7 +22,6 @@
|
||||
package com.kingsrook.qqq.backend.core.scheduler;
|
||||
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -71,16 +70,6 @@ public class StandardScheduledExecutor
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
public static String newThreadNameRandomSuffix()
|
||||
{
|
||||
return (":" + UUID.randomUUID().toString().split("-")[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
@ -108,7 +108,7 @@ public class RDBMSDeleteAction extends AbstractRDBMSAction implements DeleteInte
|
||||
catch(Exception e)
|
||||
{
|
||||
deleteInput.getAsyncJobCallback().updateStatus("Error running bulk delete via filter. Fetching keys for individual deletes.");
|
||||
LOG.info("Exception trying to delete by filter query. Moving on to deleting by id now.");
|
||||
LOG.info("Exception trying to delete by filter query. Moving on to deleting by id now.", e);
|
||||
deleteInput.setPrimaryKeys(DeleteAction.getPrimaryKeysFromQueryFilter(deleteInput));
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ import java.io.IOException;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -110,6 +112,7 @@ import io.javalin.apibuilder.EndpointGroup;
|
||||
import io.javalin.http.Context;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.json.JSONObject;
|
||||
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
|
||||
import static com.kingsrook.qqq.backend.javalin.QJavalinAccessLogger.logPairIfSlow;
|
||||
import static io.javalin.apibuilder.ApiBuilder.delete;
|
||||
@ -146,6 +149,8 @@ public class QJavalinImplementation
|
||||
|
||||
private static Javalin service;
|
||||
|
||||
private static long startTime = 0;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
@ -180,6 +185,7 @@ public class QJavalinImplementation
|
||||
QJavalinImplementation.qInstance = qInstance;
|
||||
QJavalinImplementation.javalinMetaData = javalinMetaData;
|
||||
new QInstanceValidator().validate(qInstance);
|
||||
this.startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
@ -340,6 +346,8 @@ public class QJavalinImplementation
|
||||
|
||||
get("/widget/{name}", QJavalinImplementation::widget); // todo - can we just do a slow log here?
|
||||
|
||||
get("/serverInfo", QJavalinImplementation::serverInfo);
|
||||
|
||||
////////////////////
|
||||
// process routes //
|
||||
////////////////////
|
||||
@ -349,6 +357,26 @@ public class QJavalinImplementation
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static void serverInfo(Context context)
|
||||
{
|
||||
JSONObject serverInfo = new JSONObject();
|
||||
serverInfo.put("startTimeMillis", startTime);
|
||||
serverInfo.put("startTimeHuman", Instant.ofEpochMilli(startTime));
|
||||
|
||||
long uptime = System.currentTimeMillis() - startTime;
|
||||
serverInfo.put("uptimeMillis", uptime);
|
||||
serverInfo.put("uptimeHuman", Duration.ofMillis(uptime));
|
||||
|
||||
serverInfo.put("buildId", System.getProperty("buildId", "Unspecified"));
|
||||
|
||||
context.result(serverInfo.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user