Merged feature/quartz-scheduler into integration/sprint-38

This commit is contained in:
2024-03-19 20:24:08 -05:00
22 changed files with 877 additions and 184 deletions

View File

@ -370,6 +370,14 @@ public class QPossibleValueTranslator
*******************************************************************************/
private String translatePossibleValueCustom(Serializable value, QPossibleValueSource possibleValueSource)
{
/////////////////////////////////
// null input gets null output //
/////////////////////////////////
if(value == null)
{
return (null);
}
try
{
QCustomPossibleValueProvider customPossibleValueProvider = QCodeLoader.getCustomPossibleValueProvider(possibleValueSource);

View File

@ -77,6 +77,7 @@ import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.Bulk
import com.kingsrook.qqq.backend.core.processes.implementations.bulk.insert.BulkInsertTransformStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.ExtractViaQueryStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.StreamedETLWithFrontendProcess;
import com.kingsrook.qqq.backend.core.scheduler.QScheduleManager;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.ListingHash;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
@ -159,6 +160,18 @@ public class QInstanceEnricher
}
enrichJoins();
//////////////////////////////////////////////////////////////////////////////
// if the instance DOES have 1 or more scheduler, but no schedulable types, //
// then go ahead and add the default set that qqq knows about //
//////////////////////////////////////////////////////////////////////////////
if(CollectionUtils.nullSafeHasContents(qInstance.getSchedulers()))
{
if(CollectionUtils.nullSafeIsEmpty(qInstance.getSchedulableTypes()))
{
QScheduleManager.defineDefaultSchedulableTypesInInstance(qInstance);
}
}
}

View File

@ -50,6 +50,16 @@ public abstract class QSchedulerMetaData implements TopLevelMetaDataInterface
/*******************************************************************************
**
*******************************************************************************/
public boolean mayUseInScheduledJobsTable()
{
return (true);
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -68,6 +68,16 @@ public class QuartzSchedulerMetaData extends QSchedulerMetaData
/*******************************************************************************
**
*******************************************************************************/
public boolean mayUseInScheduledJobsTable()
{
return (true);
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -61,6 +61,16 @@ public class SimpleSchedulerMetaData extends QSchedulerMetaData
/*******************************************************************************
**
*******************************************************************************/
public boolean mayUseInScheduledJobsTable()
{
return (false);
}
/*******************************************************************************
**
*******************************************************************************/

View File

@ -73,7 +73,7 @@ public class ScheduledJob extends QRecordEntity
@QField(displayFormat = DisplayFormat.COMMAS)
private Integer repeatSeconds;
@QField(isRequired = true, maxLength = 100, valueTooLongBehavior = ValueTooLongBehavior.ERROR, possibleValueSourceName = ScheduledJobType.NAME)
@QField(isRequired = true, maxLength = 100, valueTooLongBehavior = ValueTooLongBehavior.ERROR, possibleValueSourceName = ScheduledJobTypePossibleValueSource.NAME)
private String type;
@QField(isRequired = true)

View File

@ -22,102 +22,16 @@
package com.kingsrook.qqq.backend.core.model.scheduledjobs;
import com.kingsrook.qqq.backend.core.instances.QInstanceEnricher;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.PossibleValueEnum;
/*******************************************************************************
** enum of core schedulable types that QQQ schedule manager directly knows about.
**
** note though, that applications can define their own schedulable types,
** by adding SchedulableType meta-data to the QInstance, and providing classes
** that implement SchedulableRunner.
*******************************************************************************/
public enum ScheduledJobType implements PossibleValueEnum<String>
public enum ScheduledJobType
{
PROCESS,
QUEUE_PROCESSOR,
TABLE_AUTOMATIONS,
// todo - future - USER_REPORT
;
public static final String NAME = "scheduledJobType";
private final String label;
/*******************************************************************************
** Constructor
**
*******************************************************************************/
ScheduledJobType()
{
this.label = QInstanceEnricher.nameToLabel(QInstanceEnricher.inferNameFromBackendName(name()));
}
/*******************************************************************************
** Get instance by id
**
*******************************************************************************/
public static ScheduledJobType getById(String id)
{
if(id == null)
{
return (null);
}
for(ScheduledJobType value : ScheduledJobType.values())
{
if(value.name().equals(id))
{
return (value);
}
}
return (null);
}
/*******************************************************************************
** Getter for id
**
*******************************************************************************/
public String getId()
{
return name();
}
/*******************************************************************************
** Getter for label
**
*******************************************************************************/
public String getLabel()
{
return label;
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public String getPossibleValueId()
{
return name();
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public String getPossibleValueLabel()
{
return (label);
}
TABLE_AUTOMATIONS
}

View File

@ -0,0 +1,87 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.model.scheduledjobs;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.values.QCustomPossibleValueProvider;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.values.SearchPossibleValueSourceInput;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue;
import com.kingsrook.qqq.backend.core.scheduler.schedulable.SchedulableType;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
/*******************************************************************************
**
*******************************************************************************/
public class ScheduledJobTypePossibleValueSource implements QCustomPossibleValueProvider<String>
{
public static final String NAME = "scheduledJobType";
/*******************************************************************************
**
*******************************************************************************/
@Override
public QPossibleValue<String> getPossibleValue(Serializable idValue)
{
SchedulableType schedulableType = QContext.getQInstance().getSchedulableType(String.valueOf(idValue));
if(schedulableType != null)
{
return schedulableTypeToPossibleValue(schedulableType);
}
return null;
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public List<QPossibleValue<String>> search(SearchPossibleValueSourceInput input) throws QException
{
List<QPossibleValue<String>> rs = new ArrayList<>();
for(SchedulableType schedulableType : CollectionUtils.nonNullMap(QContext.getQInstance().getSchedulableTypes()).values())
{
rs.add(schedulableTypeToPossibleValue(schedulableType));
}
return rs;
}
/*******************************************************************************
**
*******************************************************************************/
private static QPossibleValue<String> schedulableTypeToPossibleValue(SchedulableType schedulableType)
{
return new QPossibleValue<>(schedulableType.getName(), schedulableType.getName());
}
}

View File

@ -45,6 +45,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.ExposedJoin;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QFieldSection;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Tier;
import com.kingsrook.qqq.backend.core.model.scheduledjobs.customizers.ScheduledJobParameterTableCustomizer;
import com.kingsrook.qqq.backend.core.model.scheduledjobs.customizers.ScheduledJobTableCustomizer;
@ -64,7 +65,7 @@ public class ScheduledJobsMetaDataProvider
{
defineStandardTables(instance, backendName, backendDetailEnricher);
instance.addPossibleValueSource(QPossibleValueSource.newForTable(ScheduledJob.TABLE_NAME));
instance.addPossibleValueSource(QPossibleValueSource.newForEnum(ScheduledJobType.NAME, ScheduledJobType.values()));
instance.addPossibleValueSource(defineScheduledJobTypePossibleValueSource());
instance.addPossibleValueSource(defineSchedulersPossibleValueSource());
defineStandardJoins(instance);
defineStandardWidgets(instance);
@ -205,6 +206,12 @@ public class ScheduledJobsMetaDataProvider
.withSection(new QFieldSection("identity", new QIcon().withName("badge"), Tier.T1, List.of("id", "scheduledJobId", "key", "value")))
.withSection(new QFieldSection("dates", new QIcon().withName("calendar_month"), Tier.T3, List.of("createDate", "modifyDate")));
QCodeReference customizerReference = new QCodeReference(ScheduledJobParameterTableCustomizer.class);
tableMetaData.withCustomizer(TableCustomizers.POST_INSERT_RECORD, customizerReference);
tableMetaData.withCustomizer(TableCustomizers.POST_UPDATE_RECORD, customizerReference);
tableMetaData.withCustomizer(TableCustomizers.POST_DELETE_RECORD, customizerReference);
tableMetaData.withExposedJoin(new ExposedJoin()
.withJoinTable(ScheduledJob.TABLE_NAME)
.withJoinPath(List.of(JOB_PARAMETER_JOIN_NAME))
@ -215,6 +222,19 @@ public class ScheduledJobsMetaDataProvider
/*******************************************************************************
**
*******************************************************************************/
private QPossibleValueSource defineScheduledJobTypePossibleValueSource()
{
return (new QPossibleValueSource()
.withName(ScheduledJobTypePossibleValueSource.NAME)
.withType(QPossibleValueSourceType.CUSTOM)
.withCustomCodeReference(new QCodeReference(ScheduledJobTypePossibleValueSource.class)));
}
/*******************************************************************************
**
*******************************************************************************/
@ -224,7 +244,6 @@ public class ScheduledJobsMetaDataProvider
.withName(SchedulersPossibleValueSource.NAME)
.withType(QPossibleValueSourceType.CUSTOM)
.withCustomCodeReference(new QCodeReference(SchedulersPossibleValueSource.class)));
}
}

View File

@ -69,7 +69,10 @@ public class SchedulersPossibleValueSource implements QCustomPossibleValueProvid
List<QPossibleValue<String>> rs = new ArrayList<>();
for(QSchedulerMetaData scheduler : CollectionUtils.nonNullMap(QContext.getQInstance().getSchedulers()).values())
{
rs.add(schedulerToPossibleValue(scheduler));
if(scheduler.mayUseInScheduledJobsTable())
{
rs.add(schedulerToPossibleValue(scheduler));
}
}
return rs;
}

View File

@ -0,0 +1,215 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.model.scheduledjobs.customizers;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import com.kingsrook.qqq.backend.core.actions.customizers.TableCustomizerInterface;
import com.kingsrook.qqq.backend.core.actions.tables.UpdateAction;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput;
import com.kingsrook.qqq.backend.core.model.actions.AbstractTableActionInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.delete.DeleteInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateInput;
import com.kingsrook.qqq.backend.core.model.actions.tables.update.UpdateOutput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.scheduledjobs.ScheduledJob;
import com.kingsrook.qqq.backend.core.model.scheduledjobs.ScheduledJobParameter;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.ListingHash;
/*******************************************************************************
**
*******************************************************************************/
public class ScheduledJobParameterTableCustomizer implements TableCustomizerInterface
{
/*******************************************************************************
**
*******************************************************************************/
@Override
public List<QRecord> postInsert(InsertInput insertInput, List<QRecord> records) throws QException
{
///////////////////////////////////////////////////////////////////////////////////////
// if we're in this insert as a result of an insert (or update) on a different table //
// (e.g., under a manageAssociations call), then return with noop - assume that the //
// parent table's customizer will do what needed to be done. //
///////////////////////////////////////////////////////////////////////////////////////
if(!isThisAnActionDirectlyOnThisTable())
{
return (records);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// else - this was an action directly on this table - so bump all of the parent records, to get them rescheduled //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bumpParentRecords(records, Optional.empty());
return (records);
}
/*******************************************************************************
**
*******************************************************************************/
private void bumpParentRecords(List<QRecord> records, Optional<List<QRecord>> oldRecordList) throws QException
{
try
{
///////////////////////////////////////////////////////////////////////////////////////////
// (listing) hash up the records by scheduledJobId - we'll use this to have a set of the //
// job ids, and in case we need to add warnings to them later //
///////////////////////////////////////////////////////////////////////////////////////////
ListingHash<Integer, QRecord> recordsByJobId = new ListingHash<>();
for(QRecord record : records)
{
recordsByJobId.add(record.getValueInteger("scheduledJobId"), record);
}
Set<Integer> scheduledJobIds = new HashSet<>(recordsByJobId.keySet());
////////////////////////////////////////////////////////////////////////////////
// if we have an old record list (e.g., is an edit), add any job ids that are //
// in those too, e.g., in case moving a param from one job to another... //
// note, we won't line these up for doing a proper warning on these... //
////////////////////////////////////////////////////////////////////////////////
if(oldRecordList.isPresent())
{
for(QRecord oldRecord : oldRecordList.get())
{
scheduledJobIds.add(oldRecord.getValueInteger("scheduledJobId"));
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// update the modify date on the scheduled jobs - to get their post-actions to run, to reschedule //
////////////////////////////////////////////////////////////////////////////////////////////////////
UpdateInput updateInput = new UpdateInput();
updateInput.setTableName(ScheduledJob.TABLE_NAME);
updateInput.setRecords(scheduledJobIds.stream()
.map(id -> new QRecord().withValue("id", id).withValue("modifyDate", Instant.now()))
.toList());
UpdateOutput updateOutput = new UpdateAction().execute(updateInput);
////////////////////////////////////////////////////////////////////////////////////////
// look for warnings on those jobs - and propagate them to the params we just stored. //
////////////////////////////////////////////////////////////////////////////////////////
for(QRecord updatedScheduledJob : updateOutput.getRecords())
{
if(CollectionUtils.nullSafeHasContents(updatedScheduledJob.getWarnings()))
{
for(QRecord paramToWarn : CollectionUtils.nonNullList(recordsByJobId.get(updatedScheduledJob.getValueInteger("id"))))
{
paramToWarn.setWarnings(updatedScheduledJob.getWarnings());
}
}
}
}
catch(Exception e)
{
LOG.warn("Error in scheduledJobParameter post-crud", e);
}
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public List<QRecord> postUpdate(UpdateInput updateInput, List<QRecord> records, Optional<List<QRecord>> oldRecordList) throws QException
{
/////////////////////////////////////////////////////////////////////////////
// if we're in this update as a result of an update on a different table //
// (e.g., under a manageAssociations call), then return with noop - assume //
// that the parent table's customizer will do what needed to be done. //
/////////////////////////////////////////////////////////////////////////////
if(!isThisAnActionDirectlyOnThisTable())
{
return (records);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// else - this was an action directly on this table - so bump all of the parent records, to get them rescheduled //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bumpParentRecords(records, oldRecordList);
return (records);
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public List<QRecord> postDelete(DeleteInput deleteInput, List<QRecord> records) throws QException
{
/////////////////////////////////////////////////////////////////////////////
// if we're in this update as a result of an update on a different table //
// (e.g., under a manageAssociations call), then return with noop - assume //
// that the parent table's customizer will do what needed to be done. //
/////////////////////////////////////////////////////////////////////////////
if(!isThisAnActionDirectlyOnThisTable())
{
return (records);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// else - this was an action directly on this table - so bump all of the parent records, to get them rescheduled //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bumpParentRecords(records, Optional.empty());
return (records);
}
/*******************************************************************************
**
*******************************************************************************/
private static boolean isThisAnActionDirectlyOnThisTable()
{
Optional<AbstractActionInput> firstActionInStack = QContext.getFirstActionInStack();
if(firstActionInStack.isPresent())
{
if(firstActionInStack.get() instanceof AbstractTableActionInput tableActionInput)
{
if(!ScheduledJobParameter.TABLE_NAME.equals(tableActionInput.getTableName()))
{
return (false);
}
}
}
return (true);
}
}

View File

@ -22,10 +22,12 @@
package com.kingsrook.qqq.backend.core.model.scheduledjobs.customizers;
import java.io.Serializable;
import java.text.ParseException;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
@ -47,6 +49,7 @@ import com.kingsrook.qqq.backend.core.model.statusmessages.QWarningMessage;
import com.kingsrook.qqq.backend.core.scheduler.QScheduleManager;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
import org.quartz.CronScheduleBuilder;
import static com.kingsrook.qqq.backend.core.logging.LogUtils.logPair;
@ -62,7 +65,7 @@ public class ScheduledJobTableCustomizer implements TableCustomizerInterface
@Override
public List<QRecord> preInsert(InsertInput insertInput, List<QRecord> records, boolean isPreview) throws QException
{
validateConditionalFields(records);
validateConditionalFields(records, Collections.emptyMap());
return (records);
}
@ -86,7 +89,9 @@ public class ScheduledJobTableCustomizer implements TableCustomizerInterface
@Override
public List<QRecord> preUpdate(UpdateInput updateInput, List<QRecord> records, boolean isPreview, Optional<List<QRecord>> oldRecordList) throws QException
{
validateConditionalFields(records);
Map<Integer, QRecord> freshOldRecordsWithAssociationsMap = CollectionUtils.recordsToMap(freshlyQueryForRecordsWithAssociations(oldRecordList.get()), "id", Integer.class);
validateConditionalFields(records, freshOldRecordsWithAssociationsMap);
if(isPreview || oldRecordList.isEmpty())
{
@ -96,8 +101,7 @@ public class ScheduledJobTableCustomizer implements TableCustomizerInterface
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// refresh the old-records w/ versions that have associations - so we can use those in the post-update to property unschedule things //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Map<Serializable, QRecord> freshOldRecordsWithAssociationsMap = CollectionUtils.recordsToMap(freshlyQueryForRecordsWithAssociations(oldRecordList.get()), "id");
ListIterator<QRecord> iterator = oldRecordList.get().listIterator();
ListIterator<QRecord> iterator = oldRecordList.get().listIterator();
while(iterator.hasNext())
{
QRecord record = iterator.next();
@ -116,20 +120,40 @@ public class ScheduledJobTableCustomizer implements TableCustomizerInterface
/*******************************************************************************
**
*******************************************************************************/
private static void validateConditionalFields(List<QRecord> records)
private static void validateConditionalFields(List<QRecord> records, Map<Integer, QRecord> freshOldRecordsWithAssociationsMap)
{
QRecord blankRecord = new QRecord();
for(QRecord record : records)
{
if(StringUtils.hasContent(record.getValueString("cronExpression")))
QRecord oldRecord = Objects.requireNonNullElse(freshOldRecordsWithAssociationsMap.get(record.getValueInteger("id")), blankRecord);
String cronExpression = record.getValues().containsKey("cronExpression") ? record.getValueString("cronExpression") : oldRecord.getValueString("cronExpression");
String cronTimeZoneId = record.getValues().containsKey("cronTimeZoneId") ? record.getValueString("cronTimeZoneId") : oldRecord.getValueString("cronTimeZoneId");
String repeatSeconds = record.getValues().containsKey("repeatSeconds") ? record.getValueString("repeatSeconds") : oldRecord.getValueString("repeatSeconds");
if(StringUtils.hasContent(cronExpression))
{
if(!StringUtils.hasContent(record.getValueString("cronTimeZoneId")))
if(StringUtils.hasContent(repeatSeconds))
{
record.addError(new BadInputStatusMessage("If a Cron Expression is given, then a Cron Time Zone Id is required."));
record.addError(new BadInputStatusMessage("Cron Expression and Repeat Seconds may not both be given."));
}
try
{
CronScheduleBuilder.cronScheduleNonvalidatedExpression(cronExpression);
}
catch(ParseException e)
{
record.addError(new BadInputStatusMessage("Cron Expression [" + cronExpression + "] is not valid: " + e.getMessage()));
}
if(!StringUtils.hasContent(cronTimeZoneId))
{
record.addError(new BadInputStatusMessage("If a Cron Expression is given, then a Cron Time Zone is required."));
}
}
else
{
if(!StringUtils.hasContent(record.getValueString("repeatSeconds")))
if(!StringUtils.hasContent(repeatSeconds))
{
record.addError(new BadInputStatusMessage("Either Cron Expression or Repeat Seconds must be given."));
}

View File

@ -102,15 +102,6 @@ public class QScheduleManager
{
qScheduleManager = new QScheduleManager(qInstance, systemUserSessionSupplier);
/////////////////////////////////////////////////////////////////
// if the instance doesn't have any schedulable types defined, //
// then go ahead and add the default set that qqq knows about //
/////////////////////////////////////////////////////////////////
if(CollectionUtils.nullSafeIsEmpty(qInstance.getSchedulableTypes()))
{
defineDefaultSchedulableTypesInInstance(qInstance);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// initialize the scheduler(s) we're configured to use //
// do this, even if we won't start them - so, for example, a web server can still be aware of schedules in the application //
@ -131,9 +122,9 @@ public class QScheduleManager
*******************************************************************************/
public static void defineDefaultSchedulableTypesInInstance(QInstance qInstance)
{
qInstance.addSchedulableType(new SchedulableType().withName(ScheduledJobType.PROCESS.getId()).withRunner(new QCodeReference(SchedulableProcessRunner.class)));
qInstance.addSchedulableType(new SchedulableType().withName(ScheduledJobType.QUEUE_PROCESSOR.getId()).withRunner(new QCodeReference(SchedulableSQSQueueRunner.class)));
qInstance.addSchedulableType(new SchedulableType().withName(ScheduledJobType.TABLE_AUTOMATIONS.getId()).withRunner(new QCodeReference(SchedulableTableAutomationsRunner.class)));
qInstance.addSchedulableType(new SchedulableType().withName(ScheduledJobType.PROCESS.name()).withRunner(new QCodeReference(SchedulableProcessRunner.class)));
qInstance.addSchedulableType(new SchedulableType().withName(ScheduledJobType.QUEUE_PROCESSOR.name()).withRunner(new QCodeReference(SchedulableSQSQueueRunner.class)));
qInstance.addSchedulableType(new SchedulableType().withName(ScheduledJobType.TABLE_AUTOMATIONS.name()).withRunner(new QCodeReference(SchedulableTableAutomationsRunner.class)));
}
@ -330,8 +321,8 @@ public class QScheduleManager
throw (new QException("Missing a type " + exceptionSuffix));
}
ScheduledJobType scheduledJobType = ScheduledJobType.getById(scheduledJob.getType());
if(scheduledJobType == null)
SchedulableType schedulableType = qInstance.getSchedulableType(scheduledJob.getType());
if(schedulableType == null)
{
throw (new QException("Unrecognized type [" + scheduledJob.getType() + "] " + exceptionSuffix));
}
@ -339,8 +330,6 @@ public class QScheduleManager
QSchedulerInterface scheduler = getScheduler(scheduledJob.getSchedulerName());
Map<String, Serializable> paramMap = new HashMap<>(scheduledJob.getJobParametersMap());
SchedulableType schedulableType = qInstance.getSchedulableType(scheduledJob.getType());
SchedulableRunner runner = QCodeLoader.getAdHoc(SchedulableRunner.class, schedulableType.getRunner());
runner.validateParams(schedulableIdentity, new HashMap<>(paramMap));
@ -396,7 +385,7 @@ public class QScheduleManager
Map<String, String> paramMap = new HashMap<>();
paramMap.put("processName", process.getName());
SchedulableType schedulableType = qInstance.getSchedulableType(ScheduledJobType.PROCESS.getId());
SchedulableType schedulableType = qInstance.getSchedulableType(ScheduledJobType.PROCESS.name());
if(process.getVariantBackend() == null || VariantRunStrategy.SERIAL.equals(process.getVariantRunStrategy()))
{
@ -446,7 +435,7 @@ public class QScheduleManager
*******************************************************************************/
private void setupTableAutomations(QTableMetaData table) throws QException
{
SchedulableType schedulableType = qInstance.getSchedulableType(ScheduledJobType.TABLE_AUTOMATIONS.getId());
SchedulableType schedulableType = qInstance.getSchedulableType(ScheduledJobType.TABLE_AUTOMATIONS.name());
QTableAutomationDetails automationDetails = table.getAutomationDetails();
QSchedulerInterface scheduler = getScheduler(automationDetails.getSchedule().getSchedulerName());
@ -475,7 +464,7 @@ public class QScheduleManager
{
SchedulableIdentity schedulableIdentity = SchedulableIdentityFactory.of(queue);
QSchedulerInterface scheduler = getScheduler(queue.getSchedule().getSchedulerName());
SchedulableType schedulableType = qInstance.getSchedulableType(ScheduledJobType.QUEUE_PROCESSOR.getId());
SchedulableType schedulableType = qInstance.getSchedulableType(ScheduledJobType.QUEUE_PROCESSOR.name());
boolean allowedToStart = SchedulerUtils.allowedToStart(queue.getName());
Map<String, String> paramMap = new HashMap<>();

View File

@ -52,11 +52,12 @@ public class PauseQuartzJobsProcess extends AbstractLoadStep implements MetaData
@Override
public QProcessMetaData produce(QInstance qInstance) throws QException
{
String tableName = "quartzTriggers";
String tableName = "quartzJobDetails";
return StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName(getClass().getSimpleName())
.withLabel("Pause Quartz Jobs")
.withPreviewMessage("This is a preview of the jobs that will be paused.")
.withTableName(tableName)
.withSourceTable(tableName)
.withDestinationTable(tableName)

View File

@ -52,11 +52,12 @@ public class ResumeQuartzJobsProcess extends AbstractLoadStep implements MetaDat
@Override
public QProcessMetaData produce(QInstance qInstance) throws QException
{
String tableName = "quartzTriggers";
String tableName = "quartzJobDetails";
return StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName(getClass().getSimpleName())
.withLabel("Resume Quartz Jobs")
.withPreviewMessage("This is a preview of the jobs that will be resumed.")
.withTableName(tableName)
.withSourceTable(tableName)
.withDestinationTable(tableName)

View File

@ -29,7 +29,6 @@ import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.model.metadata.processes.QProcessMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.queues.QQueueMetaData;
import com.kingsrook.qqq.backend.core.model.scheduledjobs.ScheduledJob;
import com.kingsrook.qqq.backend.core.model.scheduledjobs.ScheduledJobType;
import com.kingsrook.qqq.backend.core.scheduler.schedulable.SchedulableType;
import com.kingsrook.qqq.backend.core.scheduler.schedulable.runner.SchedulableRunner;
@ -45,19 +44,18 @@ public class SchedulableIdentityFactory
*******************************************************************************/
public static BasicSchedulableIdentity of(ScheduledJob scheduledJob)
{
String description = "";
ScheduledJobType scheduledJobType = ScheduledJobType.getById(scheduledJob.getType());
if(scheduledJobType != null)
String description = "";
SchedulableType schedulableType = QContext.getQInstance().getSchedulableType(scheduledJob.getType());
if(schedulableType != null)
{
try
{
SchedulableType schedulableType = QContext.getQInstance().getSchedulableType(scheduledJob.getType());
SchedulableRunner runner = QCodeLoader.getAdHoc(SchedulableRunner.class, schedulableType.getRunner());
SchedulableRunner runner = QCodeLoader.getAdHoc(SchedulableRunner.class, schedulableType.getRunner());
description = runner.getDescription(new HashMap<>(scheduledJob.getJobParametersMap()));
}
catch(Exception e)
{
description = "type: " + scheduledJobType;
description = "type: " + schedulableType.getName();
}
}

View File

@ -518,6 +518,24 @@ public class CollectionUtils
/*******************************************************************************
** Convert a collection of QRecords to a map, from one field's values out of
** those records, to the records themselves.
*******************************************************************************/
public static <T extends Serializable> Map<T, QRecord> recordsToMap(Collection<QRecord> records, String keyFieldName, Class<T> type)
{
Map<T, QRecord> rs = new HashMap<>();
for(QRecord record : nonNullCollection(records))
{
rs.put(ValueUtils.getValueAsType(type, record.getValue(keyFieldName)), record);
}
return (rs);
}
/*******************************************************************************
**
*******************************************************************************/