mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +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.TableAutomationAction;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.tables.automation.TriggerEvent;
|
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.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.CollectionUtils;
|
||||||
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
import com.kingsrook.qqq.backend.core.utils.StringUtils;
|
||||||
import org.apache.commons.lang.NotImplementedException;
|
import org.apache.commons.lang.NotImplementedException;
|
||||||
@ -178,7 +177,7 @@ public class PollingAutomationPerTableRunner implements Runnable
|
|||||||
QContext.init(instance, sessionSupplier.get());
|
QContext.init(instance, sessionSupplier.get());
|
||||||
|
|
||||||
String originalThreadName = Thread.currentThread().getName();
|
String originalThreadName = Thread.currentThread().getName();
|
||||||
Thread.currentThread().setName(name + StandardScheduledExecutor.newThreadNameRandomSuffix());
|
Thread.currentThread().setName(name);
|
||||||
LOG.info("Running " + this.getClass().getSimpleName() + "[" + name + "]");
|
LOG.info("Running " + this.getClass().getSimpleName() + "[" + name + "]");
|
||||||
|
|
||||||
try
|
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.QQueueMetaData;
|
||||||
import com.kingsrook.qqq.backend.core.model.metadata.queues.SQSQueueProviderMetaData;
|
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.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());
|
QContext.init(qInstance, sessionSupplier.get());
|
||||||
|
|
||||||
String originalThreadName = Thread.currentThread().getName();
|
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() + "]");
|
LOG.debug("Running " + this.getClass().getSimpleName() + "[" + queueMetaData.getName() + "]");
|
||||||
|
|
||||||
try
|
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.automation.polling.PollingAutomationPerTableRunner;
|
||||||
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
|
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
|
||||||
import com.kingsrook.qqq.backend.core.actions.queues.SQSQueuePoller;
|
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.context.QContext;
|
||||||
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
|
import com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter;
|
||||||
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
import com.kingsrook.qqq.backend.core.logging.QLogger;
|
||||||
@ -105,7 +104,7 @@ public class ScheduleManager
|
|||||||
String propertyValue = System.getProperty(propertyName);
|
String propertyValue = System.getProperty(propertyName);
|
||||||
if("false".equals(propertyValue))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +113,7 @@ public class ScheduleManager
|
|||||||
String envValue = qMetaDataVariableInterpreter.interpret("${env." + envName + "}");
|
String envValue = qMetaDataVariableInterpreter.interpret("${env." + envName + "}");
|
||||||
if("false".equals(envValue))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,17 +251,16 @@ public class ScheduleManager
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
private void startProcess(QProcessMetaData process)
|
private void startProcess(QProcessMetaData process)
|
||||||
{
|
{
|
||||||
CapturedContext capturedContext = QContext.capture();
|
|
||||||
|
|
||||||
Runnable runProcess = () ->
|
Runnable runProcess = () ->
|
||||||
{
|
{
|
||||||
QContext.init(capturedContext);
|
|
||||||
String originalThreadName = Thread.currentThread().getName();
|
String originalThreadName = Thread.currentThread().getName();
|
||||||
Thread.currentThread().setName("ScheduledProcess>" + process.getName() + StandardScheduledExecutor.newThreadNameRandomSuffix());
|
|
||||||
LOG.debug("Running Scheduled Process [" + process.getName() + "]");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
QContext.init(qInstance, sessionSupplier.get());
|
||||||
|
Thread.currentThread().setName("ScheduledProcess>" + process.getName());
|
||||||
|
LOG.debug("Running Scheduled Process [" + process.getName() + "]");
|
||||||
|
|
||||||
RunProcessInput runProcessInput = new RunProcessInput();
|
RunProcessInput runProcessInput = new RunProcessInput();
|
||||||
runProcessInput.setProcessName(process.getName());
|
runProcessInput.setProcessName(process.getName());
|
||||||
runProcessInput.setFrontendStepBehavior(RunProcessInput.FrontendStepBehavior.SKIP);
|
runProcessInput.setFrontendStepBehavior(RunProcessInput.FrontendStepBehavior.SKIP);
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
package com.kingsrook.qqq.backend.core.scheduler;
|
package com.kingsrook.qqq.backend.core.scheduler;
|
||||||
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
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)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
deleteInput.getAsyncJobCallback().updateStatus("Error running bulk delete via filter. Fetching keys for individual deletes.");
|
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));
|
deleteInput.setPrimaryKeys(DeleteAction.getPrimaryKeysFromQueryFilter(deleteInput));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ import java.io.IOException;
|
|||||||
import java.io.PipedInputStream;
|
import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -110,6 +112,7 @@ import io.javalin.apibuilder.EndpointGroup;
|
|||||||
import io.javalin.http.Context;
|
import io.javalin.http.Context;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.eclipse.jetty.http.HttpStatus;
|
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.core.logging.LogUtils.logPair;
|
||||||
import static com.kingsrook.qqq.backend.javalin.QJavalinAccessLogger.logPairIfSlow;
|
import static com.kingsrook.qqq.backend.javalin.QJavalinAccessLogger.logPairIfSlow;
|
||||||
import static io.javalin.apibuilder.ApiBuilder.delete;
|
import static io.javalin.apibuilder.ApiBuilder.delete;
|
||||||
@ -146,6 +149,8 @@ public class QJavalinImplementation
|
|||||||
|
|
||||||
private static Javalin service;
|
private static Javalin service;
|
||||||
|
|
||||||
|
private static long startTime = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -180,6 +185,7 @@ public class QJavalinImplementation
|
|||||||
QJavalinImplementation.qInstance = qInstance;
|
QJavalinImplementation.qInstance = qInstance;
|
||||||
QJavalinImplementation.javalinMetaData = javalinMetaData;
|
QJavalinImplementation.javalinMetaData = javalinMetaData;
|
||||||
new QInstanceValidator().validate(qInstance);
|
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("/widget/{name}", QJavalinImplementation::widget); // todo - can we just do a slow log here?
|
||||||
|
|
||||||
|
get("/serverInfo", QJavalinImplementation::serverInfo);
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// process routes //
|
// 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