@nocobase/plugin-workflow 2.2.0-beta.14 → 2.2.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/dist/client/119.e7dbd037d52d1286.js +10 -0
- package/dist/client/142.fb4936d78fc80007.js +10 -0
- package/dist/client/159.cc9a0f2d92cab2c1.js +10 -0
- package/dist/client/276.69fb2aea13bc7c37.js +10 -0
- package/dist/client/346.66d060d37843d3d1.js +10 -0
- package/dist/client/382.d37fba14a6b91b0b.js +10 -0
- package/dist/client/394.a37310b78419ad7a.js +10 -0
- package/dist/client/438.6c6409d821d8c353.js +10 -0
- package/dist/client/509.88792f5bd054b2af.js +10 -0
- package/dist/client/54.d81b710f7b4c1cd5.js +10 -0
- package/dist/client/618.1aa6c21d0f2840cb.js +10 -0
- package/dist/client/635.ff6085589e23d39b.js +10 -0
- package/dist/client/67.92c849b5dbe07c33.js +10 -0
- package/dist/client/719.f011fde3ad54571e.js +10 -0
- package/dist/client/728.711fd4f1ed7d4e6a.js +10 -0
- package/dist/client/739.49407722fca8d236.js +10 -0
- package/dist/client/759.13aab01e6912ed8d.js +10 -0
- package/dist/client/772.1ebaef11a0ac8688.js +10 -0
- package/dist/client/782.47792ce10fc0d5fb.js +10 -0
- package/dist/client/828.6880ab21513b1968.js +10 -0
- package/dist/client/87.083467b89aaf3e53.js +10 -0
- package/dist/client/938.26493fc09ba1ccbc.js +10 -0
- package/dist/client/964.5ab736effd480a42.js +10 -0
- package/dist/client/972.dd7f074d5f12e171.js +10 -0
- package/dist/client/AddNodeContext.d.ts +1 -9
- package/dist/client/BranchContext.d.ts +2 -10
- package/dist/client/FlowContext.d.ts +10 -5
- package/dist/client/NodeClipboardContext.d.ts +12 -2
- package/dist/client/NodeDragContext.d.ts +14 -2
- package/dist/client/RemoveNodeContext.d.ts +16 -2
- package/dist/client/WorkflowTasks.d.ts +26 -3
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +1 -1
- package/dist/client/nodeVariableUtils.d.ts +7 -6
- package/dist/client/nodes/calculation.d.ts +3 -75
- package/dist/client/nodes/condition.d.ts +7 -111
- package/dist/client/nodes/create.d.ts +3 -124
- package/dist/client/nodes/destroy.d.ts +2 -57
- package/dist/client/nodes/end.d.ts +2 -23
- package/dist/client/nodes/index.d.ts +2 -91
- package/dist/client/nodes/multi-conditions.d.ts +10 -48
- package/dist/client/nodes/output.d.ts +2 -44
- package/dist/client/nodes/query.d.ts +3 -255
- package/dist/client/nodes/update.d.ts +2 -117
- package/dist/client/style.d.ts +7 -27
- package/dist/client/triggers/collection.d.ts +3 -181
- package/dist/client/triggers/index.d.ts +2 -36
- package/dist/client/triggers/schedule/index.d.ts +8 -65
- package/dist/client/utils.d.ts +4 -5
- package/dist/client/variable.d.ts +7 -53
- package/dist/client-v2/119.81195bcd0d451279.js +10 -0
- package/dist/client-v2/142.a8c8df2a9abb43c5.js +10 -0
- package/dist/client-v2/159.cb221540c286cd32.js +10 -0
- package/dist/client-v2/276.7f746d899e221e2f.js +10 -0
- package/dist/client-v2/326.bdc99ad8e7590970.js +10 -0
- package/dist/client-v2/346.8c038b3c99d4fdc9.js +10 -0
- package/dist/client-v2/382.05f5482bb512b179.js +10 -0
- package/dist/client-v2/387.5e61d648d16dbf1b.js +10 -0
- package/dist/client-v2/394.515ed058e7f72797.js +10 -0
- package/dist/client-v2/438.b7df0416b66f8f64.js +10 -0
- package/dist/client-v2/513.617697f74783a611.js +10 -0
- package/dist/client-v2/54.d3daf06e53092726.js +10 -0
- package/dist/client-v2/635.14a6f21cf4f16345.js +10 -0
- package/dist/client-v2/677.7382807126d9621a.js +10 -0
- package/dist/client-v2/719.05cf070ef89a78f4.js +10 -0
- package/dist/client-v2/728.4e8322ff8fce87b9.js +10 -0
- package/dist/client-v2/739.5b60845103064f8d.js +10 -0
- package/dist/client-v2/759.7b162ad3adf450f1.js +10 -0
- package/dist/client-v2/772.8e5148d8c1518449.js +10 -0
- package/dist/client-v2/938.717e47af39485b29.js +10 -0
- package/dist/client-v2/ExecutionCanvas.d.ts +15 -0
- package/dist/client-v2/canvas/AddNodeContext.d.ts +35 -0
- package/dist/client-v2/canvas/AddNodeContext.shared.d.ts +33 -0
- package/dist/client-v2/canvas/AddNodeSlot.d.ts +20 -0
- package/dist/client-v2/canvas/Branch.d.ts +32 -0
- package/dist/client-v2/canvas/BranchContext.d.ts +29 -0
- package/dist/client-v2/canvas/BranchRenderContext.d.ts +14 -0
- package/dist/client-v2/canvas/CanvasContent.d.ts +20 -0
- package/dist/client-v2/canvas/DownstreamBranchIndex.d.ts +20 -0
- package/dist/client-v2/canvas/Instruction.d.ts +139 -0
- package/dist/{client/triggers/schedule/EndsByField.d.ts → client-v2/canvas/JobButton.d.ts} +3 -3
- package/dist/client-v2/canvas/Node.d.ts +38 -0
- package/dist/client-v2/canvas/NodeClipboardContext.d.ts +64 -0
- package/dist/client-v2/canvas/NodeConfigDrawer.d.ts +27 -0
- package/dist/client-v2/canvas/NodeDragContext.d.ts +83 -0
- package/dist/client-v2/canvas/RemoveNodeContext.d.ts +45 -0
- package/dist/client-v2/canvas/WorkflowTypedVariableInput.d.ts +16 -0
- package/dist/client-v2/canvas/WorkflowVariableInput.d.ts +40 -0
- package/dist/client-v2/canvas/WorkflowVariableJsonTextArea.d.ts +15 -0
- package/dist/client-v2/canvas/WorkflowVariableTag.d.ts +22 -0
- package/dist/client-v2/canvas/WorkflowVariableTextArea.d.ts +18 -0
- package/dist/client-v2/canvas/adaptVariableOptionToMetaTree.d.ts +48 -0
- package/dist/client-v2/canvas/addNodeController.d.ts +70 -0
- package/dist/client-v2/canvas/collectionFieldOptions.d.ts +57 -0
- package/dist/client-v2/canvas/contexts.d.ts +86 -0
- package/dist/client-v2/canvas/dropImpact.d.ts +28 -0
- package/dist/client-v2/canvas/instructionAvailability.d.ts +26 -0
- package/dist/client-v2/canvas/nodeRenderDispatch.d.ts +79 -0
- package/dist/client-v2/canvas/nodeTree.d.ts +21 -0
- package/dist/client-v2/canvas/nodeVariableUtils.d.ts +14 -0
- package/dist/client-v2/canvas/removeNodeUtils.d.ts +31 -0
- package/dist/client-v2/canvas/style.d.ts +35 -0
- package/dist/client-v2/canvas/textAreaInsertion.d.ts +14 -0
- package/dist/client-v2/canvas/useWorkflowInstruction.d.ts +23 -0
- package/dist/client-v2/canvas/useWorkflowVariableOptions.d.ts +40 -0
- package/dist/client-v2/canvas/workflowVariableConverters.d.ts +13 -0
- package/dist/client-v2/components/Calculation.d.ts +18 -0
- package/dist/client-v2/components/ExecutionStatusIcon.d.ts +18 -0
- package/dist/{client/triggers/schedule/RepeatField.d.ts → client-v2/components/ExecutionStatusTag.d.ts} +3 -4
- package/dist/client-v2/components/ExecutionViewHeader.d.ts +29 -0
- package/dist/client-v2/components/ExecutionsDropdown.d.ts +25 -0
- package/dist/client-v2/components/FilterDynamicComponent.d.ts +28 -0
- package/dist/client-v2/components/HideVariableContext.d.ts +11 -0
- package/dist/client-v2/components/JobResultModal.d.ts +11 -0
- package/dist/client-v2/components/RadioWithTooltip.d.ts +23 -0
- package/dist/client-v2/components/SyncModeSelect.d.ts +16 -0
- package/dist/{client/triggers/schedule/OnField.d.ts → client-v2/components/SyncModeTag.d.ts} +3 -3
- package/dist/client-v2/components/TestRunButton.d.ts +36 -0
- package/dist/client-v2/components/TimeoutInput.d.ts +15 -0
- package/dist/client-v2/components/WorkflowCanvasHeader.d.ts +17 -0
- package/dist/client-v2/components/WorkflowDetailsModal.d.ts +25 -0
- package/dist/client-v2/components/WorkflowEnabledSwitch.d.ts +16 -0
- package/dist/client-v2/components/WorkflowMenu.d.ts +17 -0
- package/dist/client-v2/components/WorkflowRevisionsDropdown.d.ts +15 -0
- package/dist/client-v2/components/WorkflowVariableWrapper.d.ts +25 -0
- package/dist/client-v2/components/collection/AppendsSelect.d.ts +15 -0
- package/dist/client-v2/components/collection/AssignedFieldsEditor.d.ts +24 -0
- package/dist/client-v2/components/collection/CollectionCascader.d.ts +15 -0
- package/dist/client-v2/components/collection/FieldsSelect.d.ts +16 -0
- package/dist/client-v2/components/collection/PaginationFields.d.ts +14 -0
- package/dist/client-v2/components/collection/SortFieldsInput.d.ts +19 -0
- package/dist/client-v2/components/collection/TriggerCollectionRecordSelect.d.ts +15 -0
- package/dist/client-v2/components/collection/index.d.ts +16 -0
- package/dist/client-v2/components/collection/utils.d.ts +42 -0
- package/dist/client-v2/components/formatResultForDisplay.d.ts +17 -0
- package/dist/client-v2/components/jobStatus.d.ts +27 -0
- package/dist/client-v2/components/renderEngineReference.d.ts +10 -0
- package/dist/client-v2/components/workflowCanvas.d.ts +41 -0
- package/dist/client-v2/constants.d.ts +19 -0
- package/dist/client-v2/hooks/useWorkflowRuntimePaths.d.ts +16 -0
- package/dist/client-v2/index.d.ts +48 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/client-v2/locale.d.ts +41 -0
- package/dist/{client → client-v2}/models/NodeDetailsGridModel.d.ts +1 -1
- package/dist/{client → client-v2}/models/NodeDetailsModel.d.ts +1 -1
- package/dist/{client → client-v2}/models/NodeValueModel.d.ts +1 -1
- package/dist/{client → client-v2}/models/TaskCardCommonItemModel.d.ts +1 -1
- package/dist/client-v2/models/WorkflowTasksTopbarActionModel.d.ts +18 -0
- package/dist/{client → client-v2}/models/index.d.ts +2 -0
- package/dist/client-v2/models/triggerWorkflows.d.ts +43 -0
- package/dist/client-v2/nodes/calculation.d.ts +38 -0
- package/dist/client-v2/nodes/collectionNode.d.ts +29 -0
- package/dist/client-v2/nodes/components/calculation.d.ts +11 -0
- package/dist/client-v2/nodes/components/collection.d.ts +15 -0
- package/dist/client-v2/nodes/components/condition.d.ts +25 -0
- package/dist/client-v2/nodes/components/conditionShared.d.ts +20 -0
- package/dist/client-v2/nodes/components/create.d.ts +12 -0
- package/dist/client-v2/nodes/components/destroy.d.ts +12 -0
- package/dist/{client/triggers/schedule/ScheduleConfig.d.ts → client-v2/nodes/components/end.d.ts} +1 -1
- package/dist/client-v2/nodes/components/filter.d.ts +17 -0
- package/dist/client-v2/nodes/components/multi-conditions.d.ts +13 -0
- package/dist/client-v2/nodes/components/multiConditionsShared.d.ts +20 -0
- package/dist/client-v2/nodes/components/output.d.ts +10 -0
- package/dist/client-v2/nodes/components/query.d.ts +12 -0
- package/dist/client-v2/nodes/components/update.d.ts +12 -0
- package/dist/client-v2/nodes/condition.d.ts +46 -0
- package/dist/client-v2/nodes/create.d.ts +30 -0
- package/dist/client-v2/nodes/destroy.d.ts +24 -0
- package/dist/client-v2/nodes/end.d.ts +21 -0
- package/dist/client-v2/nodes/multi-conditions.d.ts +34 -0
- package/dist/client-v2/nodes/output.d.ts +29 -0
- package/dist/client-v2/nodes/query.d.ts +32 -0
- package/dist/client-v2/nodes/update.d.ts +25 -0
- package/dist/client-v2/pages/ExecutionHistoryDrawer.d.ts +13 -0
- package/dist/client-v2/pages/ExecutionViewPage.d.ts +10 -0
- package/dist/client-v2/pages/WorkflowCanvasPage.d.ts +10 -0
- package/dist/client-v2/pages/WorkflowCategoryTabs.d.ts +25 -0
- package/dist/client-v2/pages/WorkflowFormDrawer.d.ts +40 -0
- package/dist/client-v2/pages/WorkflowPane.d.ts +10 -0
- package/dist/client-v2/pages/WorkflowTasksPage.d.ts +10 -0
- package/dist/client-v2/plugin.d.ts +119 -0
- package/dist/client-v2/taskCenter.d.ts +105 -0
- package/dist/client-v2/triggers/ExecuteWorkflowButton.d.ts +35 -0
- package/dist/client-v2/triggers/TriggerConfig.d.ts +22 -0
- package/dist/client-v2/triggers/TriggerExecutionButton.d.ts +13 -0
- package/dist/client-v2/triggers/collection/CollectionConfig.d.ts +14 -0
- package/dist/client-v2/triggers/collection/TriggerCollectionConfig.d.ts +11 -0
- package/dist/client-v2/triggers/collection/constants.d.ts +28 -0
- package/dist/client-v2/triggers/collection/index.d.ts +40 -0
- package/dist/client-v2/triggers/index.d.ts +63 -0
- package/dist/client-v2/triggers/schedule/EndsByField.d.ts +17 -0
- package/dist/client-v2/triggers/schedule/OnField.d.ts +20 -0
- package/dist/client-v2/triggers/schedule/RepeatField.d.ts +23 -0
- package/dist/client-v2/triggers/schedule/ScheduleConfig.d.ts +17 -0
- package/dist/client-v2/triggers/schedule/ScheduleModes.d.ts +41 -0
- package/dist/{client → client-v2}/triggers/schedule/TriggerScheduleConfig.d.ts +1 -0
- package/dist/{client → client-v2}/triggers/schedule/constants.d.ts +8 -5
- package/dist/client-v2/triggers/schedule/index.d.ts +40 -0
- package/dist/client-v2/triggers/schedule/locale/Cron.zh-CN.d.ts +11 -0
- package/dist/client-v2/utils/contextSingleton.d.ts +9 -0
- package/dist/common/collections/userWorkflowTaskStats.d.ts +54 -0
- package/dist/common/collections/userWorkflowTaskStats.js +87 -0
- package/dist/common/collections/workflows.d.ts +16 -0
- package/dist/common/collections/workflows.js +5 -0
- package/dist/common/defaultWorkflowFilter.d.ts +21 -0
- package/dist/common/defaultWorkflowFilter.js +38 -0
- package/dist/common/executionStatus.d.ts +44 -0
- package/dist/common/executionStatus.js +133 -0
- package/dist/externalVersion.js +16 -13
- package/dist/locale/de-DE.json +14 -1
- package/dist/locale/en-US.json +29 -1
- package/dist/locale/es-ES.json +14 -1
- package/dist/locale/fr-FR.json +14 -1
- package/dist/locale/hu-HU.json +14 -1
- package/dist/locale/id-ID.json +14 -1
- package/dist/locale/it-IT.json +14 -1
- package/dist/locale/ja-JP.json +14 -1
- package/dist/locale/ko-KR.json +14 -1
- package/dist/locale/nl-NL.json +14 -1
- package/dist/locale/pt-BR.json +14 -1
- package/dist/locale/ru-RU.json +14 -1
- package/dist/locale/tr-TR.json +14 -1
- package/dist/locale/uk-UA.json +14 -1
- package/dist/locale/vi-VN.json +14 -1
- package/dist/locale/zh-CN.json +28 -1
- package/dist/locale/zh-TW.json +20 -1
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/joi/package.json +1 -1
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/server/Dispatcher.d.ts +24 -13
- package/dist/server/Dispatcher.js +162 -144
- package/dist/server/ExecutionTimeoutManager.js +2 -1
- package/dist/server/Plugin.d.ts +57 -11
- package/dist/server/Plugin.js +355 -15
- package/dist/server/Processor.d.ts +1 -7
- package/dist/server/Processor.js +11 -7
- package/dist/server/actions/executions.js +3 -6
- package/dist/server/actions/index.js +3 -1
- package/dist/server/actions/jobs.js +1 -2
- package/dist/server/actions/userWorkflowTaskStats.d.ts +10 -0
- package/dist/server/actions/userWorkflowTaskStats.js +112 -0
- package/dist/server/actions/workflows.d.ts +1 -0
- package/dist/server/actions/workflows.js +28 -2
- package/dist/server/collections/userWorkflowTaskStats.d.ts +11 -0
- package/dist/server/collections/userWorkflowTaskStats.js +43 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/types/Execution.d.ts +2 -0
- package/dist/server/types/Job.d.ts +5 -0
- package/dist/server/types/Workflow.d.ts +1 -0
- package/dist/server/utils.d.ts +1 -0
- package/dist/server/utils.js +5 -0
- package/dist/swagger/index.d.ts +68 -1
- package/dist/swagger/index.js +61 -1
- package/package.json +4 -2
- package/dist/client/618.c91be3f6e4d73501.js +0 -10
- package/dist/client/67.6eab22df32aca212.js +0 -10
- package/dist/client/964.5e11e1820fece37b.js +0 -10
- package/dist/client/triggers/schedule/ScheduleModes.d.ts +0 -170
- package/dist/client/triggers/schedule/locale/Cron.zh-CN.d.ts +0 -42
package/dist/server/Plugin.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(Plugin_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(Plugin_exports);
|
|
43
43
|
var import_path = __toESM(require("path"));
|
|
44
44
|
var import_nodejs_snowflake = require("nodejs-snowflake");
|
|
45
|
+
var import_sequelize = require("sequelize");
|
|
45
46
|
var import_lru_cache = require("lru-cache");
|
|
46
47
|
var import_database = require("@nocobase/database");
|
|
47
48
|
var import_server = require("@nocobase/server");
|
|
@@ -53,6 +54,7 @@ var import_RunningExecutionRegistry = __toESM(require("./RunningExecutionRegistr
|
|
|
53
54
|
var import_actions = __toESM(require("./actions"));
|
|
54
55
|
var import_nodes = require("./actions/nodes");
|
|
55
56
|
var import_workflows = require("./actions/workflows");
|
|
57
|
+
var import_constants = require("./constants");
|
|
56
58
|
var import_functions = __toESM(require("./functions"));
|
|
57
59
|
var import_CollectionTrigger = __toESM(require("./triggers/CollectionTrigger"));
|
|
58
60
|
var import_ScheduleTrigger = __toESM(require("./triggers/ScheduleTrigger"));
|
|
@@ -82,6 +84,7 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
82
84
|
loggerCache;
|
|
83
85
|
meter = null;
|
|
84
86
|
checker = null;
|
|
87
|
+
taskStatsProviders = /* @__PURE__ */ new Map();
|
|
85
88
|
onBeforeSave = async (instance, { transaction, cycling }) => {
|
|
86
89
|
if (cycling) {
|
|
87
90
|
return;
|
|
@@ -170,16 +173,16 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
this.checker = setInterval(() => {
|
|
173
|
-
this.dispatcher.
|
|
176
|
+
this.dispatcher.recover({ gracePeriod: 6e4 });
|
|
174
177
|
}, 3e5);
|
|
175
178
|
await this.timeoutManager.load();
|
|
176
|
-
this.app.on("workflow:
|
|
177
|
-
this.app.logger.info("workflow:
|
|
178
|
-
this.dispatcher.
|
|
179
|
+
this.app.on("workflow:recover", () => {
|
|
180
|
+
this.app.logger.info("workflow:recover");
|
|
181
|
+
this.dispatcher.recover();
|
|
179
182
|
});
|
|
180
183
|
this.dispatcher.setReady(true);
|
|
181
184
|
this.getLogger("dispatcher").info("(starting) check for queueing executions");
|
|
182
|
-
this.dispatcher.
|
|
185
|
+
this.dispatcher.recover();
|
|
183
186
|
};
|
|
184
187
|
onBeforeStop = async () => {
|
|
185
188
|
if (this.checker) {
|
|
@@ -191,7 +194,6 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
191
194
|
for (const workflow of this.enabledCache.values()) {
|
|
192
195
|
this.toggle(workflow, false, { silent: true });
|
|
193
196
|
}
|
|
194
|
-
this.app.eventQueue.unsubscribe(this.channelPendingExecution);
|
|
195
197
|
this.loggerCache.clear();
|
|
196
198
|
};
|
|
197
199
|
async handleSyncMessage(message) {
|
|
@@ -393,6 +395,7 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
393
395
|
actions: ["workflows:list"]
|
|
394
396
|
});
|
|
395
397
|
this.app.acl.allow("userWorkflowTasks", "listMine", "loggedIn");
|
|
398
|
+
this.app.acl.allow("userWorkflowTaskStats", "listMine", "loggedIn");
|
|
396
399
|
db.on("workflows.beforeSave", this.onBeforeSave);
|
|
397
400
|
db.on("workflows.afterCreate", this.onAfterCreate);
|
|
398
401
|
db.on("workflows.afterUpdate", this.onAfterUpdate);
|
|
@@ -401,7 +404,7 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
401
404
|
this.app.on("beforeStop", this.onBeforeStop);
|
|
402
405
|
this.app.eventQueue.subscribe(this.channelPendingExecution, {
|
|
403
406
|
idle: () => this.serving() && this.dispatcher.idle,
|
|
404
|
-
process: this.dispatcher.
|
|
407
|
+
process: this.dispatcher.onQueueTask
|
|
405
408
|
});
|
|
406
409
|
}
|
|
407
410
|
toggle(workflow, enable, { silent, transaction } = {}) {
|
|
@@ -448,25 +451,70 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
448
451
|
trigger(workflow, context, options = {}) {
|
|
449
452
|
return this.dispatcher.trigger(workflow, context, options);
|
|
450
453
|
}
|
|
451
|
-
async
|
|
452
|
-
return this.dispatcher.
|
|
454
|
+
async rerun(execution, rerun) {
|
|
455
|
+
return this.dispatcher.enqueue({ executionId: this.getModelId(execution), rerun: rerun ?? {} });
|
|
453
456
|
}
|
|
454
|
-
|
|
455
|
-
return this.dispatcher.
|
|
457
|
+
recover() {
|
|
458
|
+
return this.dispatcher.recover();
|
|
456
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* Persist the current job state and publish a poke that evaluates that state.
|
|
462
|
+
*
|
|
463
|
+
* PENDING resume calls are valid for instructions such as delay and sequential approval.
|
|
464
|
+
* Callers that aggregate multiple user actions must only call this method when their
|
|
465
|
+
* atomic update changes the job from PENDING to a terminal status.
|
|
466
|
+
* Persistence and queue publication failures are logged and rethrown to awaiting callers.
|
|
467
|
+
*/
|
|
457
468
|
async resume(job) {
|
|
458
|
-
|
|
469
|
+
var _a;
|
|
470
|
+
const executionId = job.executionId ?? ((_a = job.execution) == null ? void 0 : _a.id);
|
|
471
|
+
if (executionId == null) {
|
|
472
|
+
this.getLogger("dispatcher").warn(`execution id of job (${job.id}) not found, resume ignored`);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
try {
|
|
476
|
+
if (job.changed()) {
|
|
477
|
+
await job.save();
|
|
478
|
+
}
|
|
479
|
+
} catch (error) {
|
|
480
|
+
this.getLogger("dispatcher").error(
|
|
481
|
+
`persisting job (${job.id}) before resuming execution (${executionId}) failed`,
|
|
482
|
+
{ error, executionId, jobId: job.id }
|
|
483
|
+
);
|
|
484
|
+
throw error;
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
await this.dispatcher.enqueue({ executionId, jobId: job.id });
|
|
488
|
+
this.getLogger("dispatcher").info(`execution (${executionId}) resuming from job (${job.id}) published to queue`);
|
|
489
|
+
} catch (error) {
|
|
490
|
+
this.getLogger("dispatcher").error(
|
|
491
|
+
`publishing resume task for execution (${executionId}) from job (${job.id}) failed`,
|
|
492
|
+
{ error, executionId, jobId: job.id }
|
|
493
|
+
);
|
|
494
|
+
throw error;
|
|
495
|
+
}
|
|
459
496
|
}
|
|
460
497
|
/**
|
|
461
498
|
* Start a deferred execution
|
|
462
499
|
* @experimental
|
|
463
500
|
*/
|
|
464
501
|
async start(execution) {
|
|
465
|
-
|
|
502
|
+
if (typeof execution !== "string" && typeof execution !== "number") {
|
|
503
|
+
if (execution.status !== import_constants.EXECUTION_STATUS.QUEUEING && execution.status !== import_constants.EXECUTION_STATUS.STARTED && execution.status != null) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
if (execution.status === import_constants.EXECUTION_STATUS.STARTED && execution.startedAt) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return this.dispatcher.enqueue({ executionId: this.getModelId(execution) });
|
|
466
511
|
}
|
|
467
512
|
createProcessor(execution, options = {}) {
|
|
468
513
|
return new import_Processor.default(execution, { ...options, plugin: this });
|
|
469
514
|
}
|
|
515
|
+
getModelId(input) {
|
|
516
|
+
return typeof input === "string" || typeof input === "number" ? input : input.id;
|
|
517
|
+
}
|
|
470
518
|
async execute(workflow, values, options = {}) {
|
|
471
519
|
const trigger = this.triggers.get(workflow.type);
|
|
472
520
|
if (!trigger) {
|
|
@@ -493,12 +541,304 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
493
541
|
return db.sequelize.transaction();
|
|
494
542
|
}
|
|
495
543
|
}
|
|
544
|
+
registerTaskStatsProvider(type, provider) {
|
|
545
|
+
this.taskStatsProviders.set(type, provider);
|
|
546
|
+
}
|
|
547
|
+
async getWorkflowIdsByKey(workflowKey, transaction) {
|
|
548
|
+
const WorkflowRepo = this.db.getRepository("workflows");
|
|
549
|
+
const workflows = await WorkflowRepo.find({
|
|
550
|
+
filter: {
|
|
551
|
+
key: workflowKey
|
|
552
|
+
},
|
|
553
|
+
fields: ["id"],
|
|
554
|
+
transaction
|
|
555
|
+
});
|
|
556
|
+
return workflows.map((workflow) => workflow.id);
|
|
557
|
+
}
|
|
558
|
+
buildTaskStatsFilter(options) {
|
|
559
|
+
var _a, _b, _c;
|
|
560
|
+
const filter = {};
|
|
561
|
+
if ((_a = options.userIds) == null ? void 0 : _a.length) {
|
|
562
|
+
filter.userId = options.userIds;
|
|
563
|
+
}
|
|
564
|
+
if ((_b = options.workflowKeys) == null ? void 0 : _b.length) {
|
|
565
|
+
filter.workflowKey = options.workflowKeys;
|
|
566
|
+
}
|
|
567
|
+
if ((_c = options.types) == null ? void 0 : _c.length) {
|
|
568
|
+
filter.type = options.types;
|
|
569
|
+
}
|
|
570
|
+
return filter;
|
|
571
|
+
}
|
|
572
|
+
normalizeTaskStats(stats = {}) {
|
|
573
|
+
return {
|
|
574
|
+
pending: Number(stats.pending) || 0,
|
|
575
|
+
all: Number(stats.all) || 0
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
async upsertTaskStatsRow(row, transaction) {
|
|
579
|
+
const repository = this.db.getRepository("userWorkflowTaskStats");
|
|
580
|
+
const values = {
|
|
581
|
+
userId: row.userId,
|
|
582
|
+
workflowKey: row.workflowKey,
|
|
583
|
+
type: row.type,
|
|
584
|
+
...this.normalizeTaskStats(row)
|
|
585
|
+
};
|
|
586
|
+
const record = await repository.findOne({
|
|
587
|
+
filter: {
|
|
588
|
+
userId: row.userId,
|
|
589
|
+
workflowKey: row.workflowKey,
|
|
590
|
+
type: row.type
|
|
591
|
+
},
|
|
592
|
+
transaction
|
|
593
|
+
});
|
|
594
|
+
if (record) {
|
|
595
|
+
await record.update(values, { transaction });
|
|
596
|
+
return record;
|
|
597
|
+
}
|
|
598
|
+
return repository.create({
|
|
599
|
+
values,
|
|
600
|
+
transaction
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
async refreshUserWorkflowTaskTypeStats(userId, type, { transaction } = {}) {
|
|
604
|
+
const repository = this.db.getRepository("userWorkflowTaskStats");
|
|
605
|
+
const rows = await repository.find({
|
|
606
|
+
filter: {
|
|
607
|
+
userId,
|
|
608
|
+
type
|
|
609
|
+
},
|
|
610
|
+
fields: ["pending", "all"],
|
|
611
|
+
transaction
|
|
612
|
+
});
|
|
613
|
+
const stats = rows.reduce(
|
|
614
|
+
(result, row) => ({
|
|
615
|
+
pending: result.pending + (Number(row.pending) || 0),
|
|
616
|
+
all: result.all + (Number(row.all) || 0)
|
|
617
|
+
}),
|
|
618
|
+
{ pending: 0, all: 0 }
|
|
619
|
+
);
|
|
620
|
+
await this.updateTasksStats(userId, type, stats, { transaction });
|
|
621
|
+
return stats;
|
|
622
|
+
}
|
|
623
|
+
async refreshUserWorkflowTaskWorkflowStats(userId, workflowKey, { transaction } = {}) {
|
|
624
|
+
const repository = this.db.getRepository("userWorkflowTaskStats");
|
|
625
|
+
const rows = await repository.find({
|
|
626
|
+
filter: {
|
|
627
|
+
userId,
|
|
628
|
+
workflowKey
|
|
629
|
+
},
|
|
630
|
+
fields: ["pending", "all"],
|
|
631
|
+
transaction
|
|
632
|
+
});
|
|
633
|
+
return rows.reduce(
|
|
634
|
+
(result, row) => ({
|
|
635
|
+
pending: result.pending + (Number(row.pending) || 0),
|
|
636
|
+
all: result.all + (Number(row.all) || 0)
|
|
637
|
+
}),
|
|
638
|
+
{ pending: 0, all: 0 }
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
sendTaskWorkflowStatsUpdated(userId, workflowKey, stats) {
|
|
642
|
+
if (!userId) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
this.app.emit("ws:sendToUser", {
|
|
646
|
+
userId,
|
|
647
|
+
message: {
|
|
648
|
+
type: "workflow:taskWorkflowStats:updated",
|
|
649
|
+
payload: {
|
|
650
|
+
userId,
|
|
651
|
+
workflowKey,
|
|
652
|
+
stats
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
async updateTaskStatsByWorkflow(input, { transaction } = {}) {
|
|
658
|
+
await this.upsertTaskStatsRow(
|
|
659
|
+
{
|
|
660
|
+
userId: input.userId,
|
|
661
|
+
workflowKey: input.workflowKey,
|
|
662
|
+
type: input.type,
|
|
663
|
+
...this.normalizeTaskStats(input.stats)
|
|
664
|
+
},
|
|
665
|
+
transaction
|
|
666
|
+
);
|
|
667
|
+
await this.refreshUserWorkflowTaskTypeStats(input.userId, input.type, { transaction });
|
|
668
|
+
const workflowStats = await this.refreshUserWorkflowTaskWorkflowStats(input.userId, input.workflowKey, {
|
|
669
|
+
transaction
|
|
670
|
+
});
|
|
671
|
+
this.sendTaskWorkflowStatsUpdated(input.userId, input.workflowKey, workflowStats);
|
|
672
|
+
}
|
|
673
|
+
async repairTaskStats(options = {}) {
|
|
674
|
+
const run = async (transaction) => {
|
|
675
|
+
var _a, _b;
|
|
676
|
+
const repository = this.db.getRepository("userWorkflowTaskStats");
|
|
677
|
+
const TaskStatsModel = this.db.getModel("userWorkflowTaskStats");
|
|
678
|
+
const filter = this.buildTaskStatsFilter(options);
|
|
679
|
+
const existedRows = await repository.find({
|
|
680
|
+
filter,
|
|
681
|
+
fields: ["userId", "workflowKey", "type"],
|
|
682
|
+
transaction
|
|
683
|
+
});
|
|
684
|
+
const providers = Array.from(this.taskStatsProviders.entries()).filter(([type]) => {
|
|
685
|
+
var _a2;
|
|
686
|
+
return !((_a2 = options.types) == null ? void 0 : _a2.length) || options.types.includes(type);
|
|
687
|
+
});
|
|
688
|
+
const legacyRows = providers.length ? await this.db.getRepository("userWorkflowTasks").find({
|
|
689
|
+
filter: {
|
|
690
|
+
...((_a = options.userIds) == null ? void 0 : _a.length) ? { userId: options.userIds } : {},
|
|
691
|
+
type: providers.map(([type]) => type)
|
|
692
|
+
},
|
|
693
|
+
fields: ["userId", "type"],
|
|
694
|
+
transaction
|
|
695
|
+
}) : [];
|
|
696
|
+
const collectedRows = (await Promise.all(
|
|
697
|
+
providers.map(([, provider]) => provider.collectTaskStats({ ...options, transaction }, { plugin: this }))
|
|
698
|
+
)).flat();
|
|
699
|
+
const rows = collectedRows.filter((row) => {
|
|
700
|
+
var _a2, _b2, _c;
|
|
701
|
+
if (((_a2 = options.userIds) == null ? void 0 : _a2.length) && !options.userIds.includes(row.userId)) {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
if (((_b2 = options.workflowKeys) == null ? void 0 : _b2.length) && !options.workflowKeys.includes(row.workflowKey)) {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
if (((_c = options.types) == null ? void 0 : _c.length) && !options.types.includes(row.type)) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
return true;
|
|
711
|
+
});
|
|
712
|
+
await repository.destroy({
|
|
713
|
+
filter,
|
|
714
|
+
transaction
|
|
715
|
+
});
|
|
716
|
+
const batchSize = 1e3;
|
|
717
|
+
for (let offset = 0; offset < rows.length; offset += batchSize) {
|
|
718
|
+
await TaskStatsModel.bulkCreate(rows.slice(offset, offset + batchSize), {
|
|
719
|
+
returning: false,
|
|
720
|
+
transaction
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
const typePairs = /* @__PURE__ */ new Set();
|
|
724
|
+
const workflowPairs = /* @__PURE__ */ new Set();
|
|
725
|
+
if ((_b = options.userIds) == null ? void 0 : _b.length) {
|
|
726
|
+
for (const userId of options.userIds) {
|
|
727
|
+
for (const [type] of providers) {
|
|
728
|
+
typePairs.add(`${userId}\0${type}`);
|
|
729
|
+
}
|
|
730
|
+
for (const workflowKey of options.workflowKeys ?? []) {
|
|
731
|
+
workflowPairs.add(`${userId}\0${workflowKey}`);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
for (const row of legacyRows) {
|
|
736
|
+
typePairs.add(`${row.userId}\0${row.type}`);
|
|
737
|
+
}
|
|
738
|
+
for (const row of [...existedRows, ...rows]) {
|
|
739
|
+
typePairs.add(`${row.userId}\0${row.type}`);
|
|
740
|
+
workflowPairs.add(`${row.userId}\0${row.workflowKey}`);
|
|
741
|
+
}
|
|
742
|
+
const affectedUserIds = Array.from(typePairs, (pair) => Number(pair.slice(0, pair.indexOf("\0"))));
|
|
743
|
+
const affectedTypes = Array.from(typePairs, (pair) => pair.slice(pair.indexOf("\0") + 1));
|
|
744
|
+
const categorizedRows = typePairs.size ? await TaskStatsModel.findAll({
|
|
745
|
+
attributes: ["userId", "type", [(0, import_sequelize.fn)("SUM", (0, import_sequelize.col)("pending")), "pending"], [(0, import_sequelize.fn)("SUM", (0, import_sequelize.col)("all")), "all"]],
|
|
746
|
+
where: {
|
|
747
|
+
userId: Array.from(new Set(affectedUserIds)),
|
|
748
|
+
type: Array.from(new Set(affectedTypes))
|
|
749
|
+
},
|
|
750
|
+
group: ["userId", "type"],
|
|
751
|
+
raw: true,
|
|
752
|
+
transaction
|
|
753
|
+
}) : [];
|
|
754
|
+
const categorizedMap = new Map(
|
|
755
|
+
categorizedRows.map((row) => [
|
|
756
|
+
`${row.userId}\0${row.type}`,
|
|
757
|
+
this.normalizeTaskStats({ pending: row.pending, all: row.all })
|
|
758
|
+
])
|
|
759
|
+
);
|
|
760
|
+
const categorizedValues = Array.from(typePairs, (pair) => {
|
|
761
|
+
const separatorIndex = pair.indexOf("\0");
|
|
762
|
+
return {
|
|
763
|
+
userId: Number(pair.slice(0, separatorIndex)),
|
|
764
|
+
type: pair.slice(separatorIndex + 1),
|
|
765
|
+
stats: categorizedMap.get(pair) ?? { pending: 0, all: 0 }
|
|
766
|
+
};
|
|
767
|
+
});
|
|
768
|
+
const categorizedUserIds = Array.from(new Set(affectedUserIds));
|
|
769
|
+
const categorizedTypes = Array.from(new Set(affectedTypes));
|
|
770
|
+
if (categorizedUserIds.length && categorizedTypes.length) {
|
|
771
|
+
await this.db.getRepository("userWorkflowTasks").destroy({
|
|
772
|
+
filter: {
|
|
773
|
+
userId: categorizedUserIds,
|
|
774
|
+
type: categorizedTypes
|
|
775
|
+
},
|
|
776
|
+
transaction
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
const UserTasksModel = this.db.getModel("userWorkflowTasks");
|
|
780
|
+
for (let offset = 0; offset < categorizedValues.length; offset += batchSize) {
|
|
781
|
+
await UserTasksModel.bulkCreate(categorizedValues.slice(offset, offset + batchSize), {
|
|
782
|
+
returning: false,
|
|
783
|
+
transaction
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
if (options.silent) {
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
for (const value of categorizedValues) {
|
|
790
|
+
if (!value.userId) {
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
this.app.emit("ws:sendToUser", {
|
|
794
|
+
userId: value.userId,
|
|
795
|
+
message: { type: "workflow:tasks:updated", payload: value }
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
const affectedWorkflowUserIds = Array.from(workflowPairs, (pair) => Number(pair.slice(0, pair.indexOf("\0"))));
|
|
799
|
+
const affectedWorkflowKeys = Array.from(workflowPairs, (pair) => pair.slice(pair.indexOf("\0") + 1));
|
|
800
|
+
const workflowRows = workflowPairs.size ? await TaskStatsModel.findAll({
|
|
801
|
+
attributes: [
|
|
802
|
+
"userId",
|
|
803
|
+
"workflowKey",
|
|
804
|
+
[(0, import_sequelize.fn)("SUM", (0, import_sequelize.col)("pending")), "pending"],
|
|
805
|
+
[(0, import_sequelize.fn)("SUM", (0, import_sequelize.col)("all")), "all"]
|
|
806
|
+
],
|
|
807
|
+
where: {
|
|
808
|
+
userId: Array.from(new Set(affectedWorkflowUserIds)),
|
|
809
|
+
workflowKey: Array.from(new Set(affectedWorkflowKeys))
|
|
810
|
+
},
|
|
811
|
+
group: ["userId", "workflowKey"],
|
|
812
|
+
raw: true,
|
|
813
|
+
transaction
|
|
814
|
+
}) : [];
|
|
815
|
+
const workflowMap = new Map(
|
|
816
|
+
workflowRows.map((row) => [
|
|
817
|
+
`${row.userId}\0${row.workflowKey}`,
|
|
818
|
+
this.normalizeTaskStats({ pending: row.pending, all: row.all })
|
|
819
|
+
])
|
|
820
|
+
);
|
|
821
|
+
for (const pair of workflowPairs) {
|
|
822
|
+
const separatorIndex = pair.indexOf("\0");
|
|
823
|
+
const userId = Number(pair.slice(0, separatorIndex));
|
|
824
|
+
const workflowKey = pair.slice(separatorIndex + 1);
|
|
825
|
+
this.sendTaskWorkflowStatsUpdated(userId, workflowKey, workflowMap.get(pair) ?? { pending: 0, all: 0 });
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
if (options.transaction) {
|
|
829
|
+
await run(options.transaction);
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
await this.db.sequelize.transaction(run);
|
|
833
|
+
}
|
|
496
834
|
/**
|
|
497
835
|
* @experimental
|
|
836
|
+
* @deprecated Use updateTaskStatsByWorkflow() when workflowKey is available.
|
|
498
837
|
*/
|
|
499
838
|
async updateTasksStats(userId, type, stats = { pending: 0, all: 0 }, { transaction }) {
|
|
500
839
|
const { db } = this.app;
|
|
501
840
|
const repository = db.getRepository("userWorkflowTasks");
|
|
841
|
+
const normalizedStats = this.normalizeTaskStats(stats);
|
|
502
842
|
let record = await repository.findOne({
|
|
503
843
|
filter: {
|
|
504
844
|
userId,
|
|
@@ -509,7 +849,7 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
509
849
|
if (record) {
|
|
510
850
|
await record.update(
|
|
511
851
|
{
|
|
512
|
-
stats
|
|
852
|
+
stats: normalizedStats
|
|
513
853
|
},
|
|
514
854
|
{ transaction }
|
|
515
855
|
);
|
|
@@ -518,7 +858,7 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
518
858
|
values: {
|
|
519
859
|
userId,
|
|
520
860
|
type,
|
|
521
|
-
stats
|
|
861
|
+
stats: normalizedStats
|
|
522
862
|
},
|
|
523
863
|
transaction
|
|
524
864
|
});
|
|
@@ -101,13 +101,7 @@ export default class Processor {
|
|
|
101
101
|
prepare(): Promise<void>;
|
|
102
102
|
start(): Promise<any>;
|
|
103
103
|
resume(job: JobModel): Promise<void>;
|
|
104
|
-
resolveRerun
|
|
105
|
-
node: FlowNodeModel;
|
|
106
|
-
input: JobModel | {
|
|
107
|
-
result: any;
|
|
108
|
-
};
|
|
109
|
-
targetJob: JobModel;
|
|
110
|
-
};
|
|
104
|
+
private resolveRerun;
|
|
111
105
|
rerun(options?: ProcessorRerunOptions): Promise<any>;
|
|
112
106
|
private getRerunNode;
|
|
113
107
|
private getRerunInput;
|
package/dist/server/Processor.js
CHANGED
|
@@ -46,6 +46,7 @@ var import_utils = require("@nocobase/utils");
|
|
|
46
46
|
var import_set = __toESM(require("lodash/set"));
|
|
47
47
|
var import_constants = require("./constants");
|
|
48
48
|
var import_timeout_errors = require("./timeout-errors");
|
|
49
|
+
const JOB_SAVE_BATCH_SIZE = 100;
|
|
49
50
|
const OPEN_SCOPE_PENDING_ERROR = "Pending jobs are not allowed inside an open transaction scope";
|
|
50
51
|
class Processor {
|
|
51
52
|
constructor(execution, options) {
|
|
@@ -488,14 +489,17 @@ class Processor {
|
|
|
488
489
|
}
|
|
489
490
|
if (newJobs.length) {
|
|
490
491
|
const JobsModel = this.options.plugin.db.getModel("jobs");
|
|
491
|
-
|
|
492
|
-
newJobs.
|
|
493
|
-
|
|
494
|
-
|
|
492
|
+
for (let offset = 0; offset < newJobs.length; offset += JOB_SAVE_BATCH_SIZE) {
|
|
493
|
+
const batch = newJobs.slice(offset, offset + JOB_SAVE_BATCH_SIZE);
|
|
494
|
+
await JobsModel.bulkCreate(
|
|
495
|
+
batch.map((job) => job.toJSON()),
|
|
496
|
+
{
|
|
497
|
+
returning: false
|
|
498
|
+
}
|
|
499
|
+
);
|
|
500
|
+
for (const job of batch) {
|
|
501
|
+
job.isNewRecord = false;
|
|
495
502
|
}
|
|
496
|
-
);
|
|
497
|
-
for (const job of newJobs) {
|
|
498
|
-
job.isNewRecord = false;
|
|
499
503
|
}
|
|
500
504
|
}
|
|
501
505
|
this.jobsToSave.clear();
|
|
@@ -98,12 +98,9 @@ async function rerun(context, next) {
|
|
|
98
98
|
if (execution.status !== import_constants.EXECUTION_STATUS.STARTED) {
|
|
99
99
|
return context.throw(400, "Only started executions can be rerun");
|
|
100
100
|
}
|
|
101
|
-
await workflowPlugin.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
nodeId,
|
|
105
|
-
overwrite: overwrite === true
|
|
106
|
-
}
|
|
101
|
+
await workflowPlugin.rerun(execution, {
|
|
102
|
+
nodeId,
|
|
103
|
+
overwrite: overwrite === true
|
|
107
104
|
});
|
|
108
105
|
context.body = execution;
|
|
109
106
|
context.status = 202;
|
|
@@ -44,6 +44,7 @@ var nodes = __toESM(require("./nodes"));
|
|
|
44
44
|
var jobs = __toESM(require("./jobs"));
|
|
45
45
|
var executions = __toESM(require("./executions"));
|
|
46
46
|
var userWorkflowTasks = __toESM(require("./userWorkflowTasks"));
|
|
47
|
+
var userWorkflowTaskStats = __toESM(require("./userWorkflowTaskStats"));
|
|
47
48
|
function make(name, mod) {
|
|
48
49
|
return Object.keys(mod).reduce(
|
|
49
50
|
(result, key) => ({
|
|
@@ -69,6 +70,7 @@ function actions_default({ app }) {
|
|
|
69
70
|
}),
|
|
70
71
|
...make("jobs", jobs),
|
|
71
72
|
...make("executions", executions),
|
|
72
|
-
...make("userWorkflowTasks", userWorkflowTasks)
|
|
73
|
+
...make("userWorkflowTasks", userWorkflowTasks),
|
|
74
|
+
...make("userWorkflowTaskStats", userWorkflowTaskStats)
|
|
73
75
|
});
|
|
74
76
|
}
|
|
@@ -82,8 +82,7 @@ async function resume(context, next) {
|
|
|
82
82
|
context.body = job;
|
|
83
83
|
context.status = 202;
|
|
84
84
|
await next();
|
|
85
|
-
job
|
|
86
|
-
workflowPlugin.resume(job);
|
|
85
|
+
await workflowPlugin.resume(job);
|
|
87
86
|
}
|
|
88
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
88
|
0 && (module.exports = {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
import { Context } from '@nocobase/actions';
|
|
10
|
+
export declare function listMine(context: Context, next: any): Promise<void>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var userWorkflowTaskStats_exports = {};
|
|
28
|
+
__export(userWorkflowTaskStats_exports, {
|
|
29
|
+
listMine: () => listMine
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(userWorkflowTaskStats_exports);
|
|
32
|
+
var import_actions = require("@nocobase/actions");
|
|
33
|
+
async function listMine(context, next) {
|
|
34
|
+
const { type, search } = context.action.params;
|
|
35
|
+
const normalizedSearch = typeof search === "string" ? search.trim() : "";
|
|
36
|
+
const page = Math.max(Number.parseInt(String(context.action.params.page ?? 1), 10) || 1, 1);
|
|
37
|
+
const pageSize = Math.min(
|
|
38
|
+
Math.max(Number.parseInt(String(context.action.params.pageSize ?? 200), 10) || 200, 1),
|
|
39
|
+
200
|
|
40
|
+
);
|
|
41
|
+
const pagination = import_actions.utils.pageArgsToLimitArgs(page, pageSize);
|
|
42
|
+
const repository = context.db.getRepository("userWorkflowTaskStats");
|
|
43
|
+
const rows = await repository.find({
|
|
44
|
+
filter: {
|
|
45
|
+
userId: context.state.currentUser.id,
|
|
46
|
+
...type ? { type } : {},
|
|
47
|
+
all: {
|
|
48
|
+
$gt: 0
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
fields: ["workflowKey", "pending", "all"]
|
|
52
|
+
});
|
|
53
|
+
const statsMap = /* @__PURE__ */ new Map();
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
if (!row.workflowKey) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const existed = statsMap.get(row.workflowKey) ?? {
|
|
59
|
+
workflowKey: row.workflowKey,
|
|
60
|
+
stats: { pending: 0, all: 0 }
|
|
61
|
+
};
|
|
62
|
+
existed.stats.pending += Number(row.pending) || 0;
|
|
63
|
+
existed.stats.all += Number(row.all) || 0;
|
|
64
|
+
statsMap.set(row.workflowKey, existed);
|
|
65
|
+
}
|
|
66
|
+
const workflowKeys = Array.from(statsMap.keys());
|
|
67
|
+
if (!workflowKeys.length) {
|
|
68
|
+
context.body = {
|
|
69
|
+
rows: [],
|
|
70
|
+
page,
|
|
71
|
+
pageSize,
|
|
72
|
+
hasNext: false
|
|
73
|
+
};
|
|
74
|
+
await next();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const workflows = await context.db.getRepository("workflows").find({
|
|
78
|
+
filter: {
|
|
79
|
+
key: workflowKeys,
|
|
80
|
+
current: true,
|
|
81
|
+
...normalizedSearch ? {
|
|
82
|
+
title: {
|
|
83
|
+
$includes: normalizedSearch
|
|
84
|
+
}
|
|
85
|
+
} : {}
|
|
86
|
+
},
|
|
87
|
+
fields: ["key", "title"],
|
|
88
|
+
sort: ["title"],
|
|
89
|
+
limit: pagination.limit + 1,
|
|
90
|
+
offset: pagination.offset
|
|
91
|
+
});
|
|
92
|
+
const hasNext = workflows.length > pageSize;
|
|
93
|
+
const data = workflows.slice(0, pageSize).map((workflow) => {
|
|
94
|
+
var _a;
|
|
95
|
+
return {
|
|
96
|
+
workflowKey: workflow.key,
|
|
97
|
+
title: workflow.title,
|
|
98
|
+
stats: ((_a = statsMap.get(workflow.key)) == null ? void 0 : _a.stats) ?? { pending: 0, all: 0 }
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
context.body = {
|
|
102
|
+
rows: data,
|
|
103
|
+
page,
|
|
104
|
+
pageSize,
|
|
105
|
+
hasNext
|
|
106
|
+
};
|
|
107
|
+
await next();
|
|
108
|
+
}
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
listMine
|
|
112
|
+
});
|
|
@@ -12,6 +12,7 @@ export declare class WorkflowValidationError extends Error {
|
|
|
12
12
|
errors: Record<string, string>;
|
|
13
13
|
constructor(errors: Record<string, string>);
|
|
14
14
|
}
|
|
15
|
+
export declare function list(context: Context, next: any): Promise<void>;
|
|
15
16
|
export declare function create(context: Context, next: any): Promise<void>;
|
|
16
17
|
export declare function update(context: Context, next: any): Promise<void>;
|
|
17
18
|
export declare function destroy(context: Context, next: any): Promise<void>;
|