From 40afb629e7eb6e2df8bf629a085fda2893e222ee Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Wed, 30 Nov 2022 11:06:40 -0600 Subject: [PATCH] Add overrideBatchSize to table automation details --- .../PollingAutomationPerTableRunner.java | 20 ++++++---- .../automation/QTableAutomationDetails.java | 37 +++++++++++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/automation/polling/PollingAutomationPerTableRunner.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/automation/polling/PollingAutomationPerTableRunner.java index abe49edb..78692fde 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/automation/polling/PollingAutomationPerTableRunner.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/automation/polling/PollingAutomationPerTableRunner.java @@ -52,6 +52,7 @@ import com.kingsrook.qqq.backend.core.model.data.QRecord; import com.kingsrook.qqq.backend.core.model.metadata.QInstance; import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData; import com.kingsrook.qqq.backend.core.model.metadata.tables.automation.AutomationStatusTrackingType; +import com.kingsrook.qqq.backend.core.model.metadata.tables.automation.QTableAutomationDetails; 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; @@ -210,18 +211,22 @@ public class PollingAutomationPerTableRunner implements Runnable /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // run an async-pipe loop - that will query for records in PENDING - put them in a pipe - then apply actions to them // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - RecordPipe recordPipe = new RecordPipe(); - AsyncRecordPipeLoop asyncRecordPipeLoop = new AsyncRecordPipeLoop(); - asyncRecordPipeLoop.run("PollingAutomationRunner>Query>" + automationStatus, null, recordPipe, (status) -> + QTableAutomationDetails automationDetails = table.getAutomationDetails(); + AsyncRecordPipeLoop asyncRecordPipeLoop = new AsyncRecordPipeLoop(); + + RecordPipe recordPipe = automationDetails.getOverrideBatchSize() == null + ? new RecordPipe() : new RecordPipe(automationDetails.getOverrideBatchSize()); + + asyncRecordPipeLoop.run("PollingAutomationRunner>Query>" + automationStatus + ">" + table.getName(), null, recordPipe, (status) -> { QueryInput queryInput = new QueryInput(instance); queryInput.setSession(session); queryInput.setTableName(table.getName()); - AutomationStatusTrackingType statusTrackingType = table.getAutomationDetails().getStatusTracking().getType(); + AutomationStatusTrackingType statusTrackingType = automationDetails.getStatusTracking().getType(); if(AutomationStatusTrackingType.FIELD_IN_TABLE.equals(statusTrackingType)) { - queryInput.setFilter(new QQueryFilter().withCriteria(new QFilterCriteria(table.getAutomationDetails().getStatusTracking().getFieldName(), QCriteriaOperator.EQUALS, List.of(automationStatus.getId())))); + queryInput.setFilter(new QQueryFilter().withCriteria(new QFilterCriteria(automationDetails.getStatusTracking().getFieldName(), QCriteriaOperator.EQUALS, List.of(automationStatus.getId())))); } else { @@ -274,7 +279,7 @@ public class PollingAutomationPerTableRunner implements Runnable if(CollectionUtils.nullSafeHasContents(matchingQRecords)) { LOG.debug(" Processing " + matchingQRecords.size() + " records in " + table + " for action " + action); - applyActionToMatchingRecords(session, table, matchingQRecords, action); + applyActionToMatchingRecords(instance, session, table, matchingQRecords, action); } } catch(Exception e) @@ -352,8 +357,9 @@ public class PollingAutomationPerTableRunner implements Runnable /******************************************************************************* ** Finally, actually run action code against a list of known matching records. + ** todo not commit - move to somewhere genericer *******************************************************************************/ - private void applyActionToMatchingRecords(QSession session, QTableMetaData table, List records, TableAutomationAction action) throws Exception + public static void applyActionToMatchingRecords(QInstance instance, QSession session, QTableMetaData table, List records, TableAutomationAction action) throws Exception { if(StringUtils.hasContent(action.getProcessName())) { diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/automation/QTableAutomationDetails.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/automation/QTableAutomationDetails.java index 3be1f343..b075d0a9 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/automation/QTableAutomationDetails.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/metadata/tables/automation/QTableAutomationDetails.java @@ -35,6 +35,8 @@ public class QTableAutomationDetails private String providerName; private List actions; + private Integer overrideBatchSize; + /******************************************************************************* @@ -151,4 +153,39 @@ public class QTableAutomationDetails this.actions.add(action); return (this); } + + + + /******************************************************************************* + ** Getter for overrideBatchSize + ** + *******************************************************************************/ + public Integer getOverrideBatchSize() + { + return overrideBatchSize; + } + + + + /******************************************************************************* + ** Setter for overrideBatchSize + ** + *******************************************************************************/ + public void setOverrideBatchSize(Integer overrideBatchSize) + { + this.overrideBatchSize = overrideBatchSize; + } + + + + /******************************************************************************* + ** Fluent setter for overrideBatchSize + ** + *******************************************************************************/ + public QTableAutomationDetails withOverrideBatchSize(Integer overrideBatchSize) + { + this.overrideBatchSize = overrideBatchSize; + return (this); + } + }