Add /run endpoint for running processes w/o any frontend

This commit is contained in:
2023-01-26 11:18:05 -06:00
parent 56f05c74fc
commit ed5839aa0a
5 changed files with 98 additions and 9 deletions

View File

@ -70,6 +70,7 @@ public class ChildRecordListRenderer extends AbstractWidgetRenderer
{
return (new Builder(new QWidgetMetaData()
.withName(join.getName())
.withIsCard(true)
.withCodeReference(new QCodeReference(ChildRecordListRenderer.class, null))
.withType(WidgetType.CHILD_RECORD_LIST.getType())
.withDefaultValue("joinName", join.getName())));

View File

@ -0,0 +1,46 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2023. Kingsrook, LLC
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
* contact@kingsrook.com
* https://github.com/Kingsrook/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.kingsrook.qqq.backend.core.instances;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/*******************************************************************************
** Unit test for SecretsManagerUtils
*******************************************************************************/
class SecretsManagerUtilsTest
{
/*******************************************************************************
**
*******************************************************************************/
@Test
void testSecretsManagerWithoutVars()
{
Optional<String> secret = SecretsManagerUtils.getSecret("foo", "bar");
assertTrue(secret.isEmpty());
}
}

View File

@ -50,8 +50,6 @@ import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
import com.kingsrook.qqq.backend.core.actions.reporting.GenerateReportAction;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.actions.values.QValueFormatter;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.exceptions.QModuleDispatchException;
import com.kingsrook.qqq.backend.core.exceptions.QNotFoundException;
import com.kingsrook.qqq.backend.core.exceptions.QPermissionDeniedException;
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
@ -119,6 +117,9 @@ public class QJavalinProcessHandler
get("/init", QJavalinProcessHandler::processInit);
post("/init", QJavalinProcessHandler::processInit);
get("/run", QJavalinProcessHandler::processRun);
post("/run", QJavalinProcessHandler::processRun);
path("/{processUUID}", () ->
{
post("/step/{step}", QJavalinProcessHandler::processStep);
@ -290,9 +291,23 @@ public class QJavalinProcessHandler
** Init a process (named in path param :process)
**
*******************************************************************************/
public static void processInit(Context context) throws QException
public static void processInit(Context context)
{
doProcessInitOrStep(context, null, null);
doProcessInitOrStep(context, null, null, RunProcessInput.FrontendStepBehavior.BREAK);
}
/*******************************************************************************
** Run a process (named in path param :process) - that is - fully run, not
** breaking on frontend steps. Note, we may still go Async - use query or
** form body param `_qStepTimeoutMillis` to set a higher timeout to get more
** synchronous-like behavior.
**
*******************************************************************************/
public static void processRun(Context context)
{
doProcessInitOrStep(context, null, null, RunProcessInput.FrontendStepBehavior.SKIP);
}
@ -300,7 +315,7 @@ public class QJavalinProcessHandler
/*******************************************************************************
**
*******************************************************************************/
private static void doProcessInitOrStep(Context context, String processUUID, String startAfterStep)
private static void doProcessInitOrStep(Context context, String processUUID, String startAfterStep, RunProcessInput.FrontendStepBehavior frontendStepBehavior)
{
Map<String, Object> resultForCaller = new HashMap<>();
Exception returningException = null;
@ -321,7 +336,7 @@ public class QJavalinProcessHandler
QJavalinImplementation.setupSession(context, runProcessInput);
runProcessInput.setProcessName(processName);
runProcessInput.setFrontendStepBehavior(RunProcessInput.FrontendStepBehavior.BREAK);
runProcessInput.setFrontendStepBehavior(frontendStepBehavior);
runProcessInput.setProcessUUID(processUUID);
runProcessInput.setStartAfterStep(startAfterStep);
populateRunProcessRequestWithValuesFromContext(context, runProcessInput);
@ -518,7 +533,7 @@ public class QJavalinProcessHandler
*******************************************************************************/
private static void archiveUploadedFile(RunProcessInput runProcessInput, QUploadedFile qUploadedFile)
{
String fileName = new QValueFormatter().formatDate(LocalDate.now())
String fileName = QValueFormatter.formatDate(LocalDate.now())
+ File.separator + runProcessInput.getProcessName()
+ File.separator + qUploadedFile.getFilename();
@ -588,11 +603,11 @@ public class QJavalinProcessHandler
** Run a step in a process (named in path param :processName)
**
*******************************************************************************/
public static void processStep(Context context) throws QModuleDispatchException
public static void processStep(Context context)
{
String processUUID = context.pathParam("processUUID");
String lastStep = context.pathParam("step");
doProcessInitOrStep(context, processUUID, lastStep);
doProcessInitOrStep(context, processUUID, lastStep, RunProcessInput.FrontendStepBehavior.BREAK);
}

View File

@ -250,6 +250,7 @@ class QJavalinProcessHandlerTest extends QJavalinTestBase
String nextStep = jsonObject.getString("nextStep");
assertNotNull(processUUID, "Process UUID should not be null.");
assertNotNull(nextStep, "There should be a next step");
assertFalse(jsonObject.getJSONObject("values").has("didSleep"), "There should not (yet) be a value from the backend step");
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// second, run the 'nextStep' (the backend step, that sleeps). run it with a long enough sleep so that it'll go async //
@ -274,6 +275,31 @@ class QJavalinProcessHandlerTest extends QJavalinTestBase
String nextStep2 = jsonObject.getString("nextStep");
assertNotNull(nextStep2, "There be one more next step");
assertNotEquals(nextStep, nextStep2, "The next step should be different this time.");
assertTrue(jsonObject.getJSONObject("values").has("didSleep"), "There should be a value from the backend step");
}
/*******************************************************************************
** test fully running a process that has frontend steps - and observing that we
** don't stop on them.
**
*******************************************************************************/
@Test
public void test_processRunWithoutBreakingForFrontendSteps() throws InterruptedException
{
/////////////////////////////////////////////
// first init the process, to get its UUID //
/////////////////////////////////////////////
String processBasePath = BASE_URL + "/processes/" + TestUtils.PROCESS_NAME_SLEEP_INTERACTIVE;
HttpResponse<String> response = Unirest.post(processBasePath + "/run?" + TestUtils.SleeperStep.FIELD_SLEEP_MILLIS + "=" + LESS_THAN_TIMEOUT)
.header("Content-Type", "application/json").asString();
JSONObject jsonObject = assertProcessStepCompleteResponse(response);
String processUUID = jsonObject.getString("processUUID");
assertNotNull(processUUID, "Process UUID should not be null.");
assertFalse(jsonObject.has("nextStep"), "There should not be a next step");
assertTrue(jsonObject.getJSONObject("values").has("didSleep"), "There should be a value from the backend step");
}

View File

@ -402,6 +402,7 @@ public class TestUtils
try
{
Thread.sleep(runBackendStepInput.getValueInteger(FIELD_SLEEP_MILLIS));
runBackendStepOutput.addValue("didSleep", true);
}
catch(InterruptedException e)
{