@nocobase/plugin-workflow 1.7.0-beta.8 → 1.7.0
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/dist/client/3c67def1831d0b23.js +10 -0
- package/dist/client/WorkflowCategoryTabs.d.ts +10 -0
- package/dist/client/WorkflowCollectionsProvider.d.ts +10 -0
- package/dist/client/WorkflowTasks.d.ts +12 -3
- package/dist/client/a4111333ce86663c.js +10 -0
- package/dist/client/a54c8c009524b6da.js +10 -0
- package/dist/client/components/EmunerationField.d.ts +9 -0
- package/dist/client/f9eeb46e5c6a9ffe.js +10 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +1 -1
- package/dist/client/locale/index.d.ts +2 -1
- package/dist/client/schemas/executions.d.ts +126 -125
- package/dist/client/triggers/schedule/RepeatField.d.ts +2 -1
- package/dist/common/collections/executions.d.ts +136 -0
- package/dist/common/collections/executions.js +125 -0
- package/dist/common/collections/flow_nodes.d.ts +65 -0
- package/dist/common/collections/flow_nodes.js +94 -0
- package/dist/common/collections/jobs.d.ts +37 -0
- package/dist/common/collections/jobs.js +74 -0
- package/dist/common/collections/userWorkflowTasks.d.ts +37 -0
- package/dist/common/collections/userWorkflowTasks.js +65 -0
- package/dist/common/collections/workflowCategories.d.ts +65 -0
- package/dist/common/collections/workflowCategories.js +68 -0
- package/dist/common/collections/workflowCategoryRelations.d.ts +21 -0
- package/dist/common/collections/workflowCategoryRelations.js +51 -0
- package/dist/common/collections/workflowStats.d.ts +37 -0
- package/dist/common/collections/workflowStats.js +59 -0
- package/dist/common/collections/workflowTasks.d.ts +10 -0
- package/dist/common/collections/workflowTasks.js +64 -0
- package/dist/common/collections/workflowVersionStats.d.ts +37 -0
- package/dist/common/collections/workflowVersionStats.js +59 -0
- package/dist/common/collections/workflows.d.ts +263 -0
- package/dist/common/collections/workflows.js +244 -0
- package/dist/common/constants.d.ts +9 -0
- package/dist/{server/actions/workflowTasks.js → common/constants.js} +6 -17
- package/dist/externalVersion.js +15 -14
- package/dist/locale/en-US.json +127 -15
- package/dist/locale/zh-CN.json +10 -1
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/LICENSE +201 -0
- package/dist/node_modules/nodejs-snowflake/nodejs_snowflake.d.ts +62 -0
- package/dist/node_modules/nodejs-snowflake/nodejs_snowflake.js +1 -0
- package/dist/node_modules/nodejs-snowflake/nodejs_snowflake_bg.wasm +0 -0
- package/dist/node_modules/nodejs-snowflake/package.json +1 -0
- package/dist/server/Dispatcher.d.ts +11 -0
- package/dist/server/Dispatcher.js +35 -0
- package/dist/server/Plugin.d.ts +12 -2
- package/dist/server/Plugin.js +143 -105
- package/dist/server/Processor.d.ts +4 -11
- package/dist/server/Processor.js +50 -45
- package/dist/server/actions/index.js +2 -2
- package/dist/server/actions/nodes.js +7 -5
- package/dist/server/actions/{workflowTasks.d.ts → userWorkflowTasks.d.ts} +1 -1
- package/dist/server/actions/userWorkflowTasks.js +54 -0
- package/dist/server/actions/workflows.js +6 -3
- package/dist/server/collections/executions.js +12 -44
- package/dist/server/collections/flow_nodes.js +12 -57
- package/dist/server/collections/jobs.js +12 -36
- package/dist/server/collections/userWorkflowTasks.d.ts +11 -0
- package/dist/server/collections/userWorkflowTasks.js +43 -0
- package/dist/server/collections/workflowCategories.d.ts +11 -0
- package/dist/server/collections/workflowCategories.js +43 -0
- package/dist/server/collections/workflowCategoryRelations.d.ts +11 -0
- package/dist/server/collections/workflowCategoryRelations.js +43 -0
- package/dist/server/collections/workflowStats.d.ts +11 -0
- package/dist/server/collections/workflowStats.js +43 -0
- package/dist/server/collections/workflowTasks.d.ts +2 -1
- package/dist/server/collections/workflowTasks.js +12 -33
- package/dist/server/collections/workflowVersionStats.d.ts +11 -0
- package/dist/server/collections/workflowVersionStats.js +43 -0
- package/dist/server/collections/workflows.d.ts +2 -1
- package/dist/server/collections/workflows.js +12 -101
- package/dist/server/migrations/20250320223415-stats.d.ts +14 -0
- package/dist/server/migrations/20250320223415-stats.js +82 -0
- package/dist/server/migrations/20250409164913-remove-jobs-auto-increment.d.ts +14 -0
- package/dist/server/migrations/20250409164913-remove-jobs-auto-increment.js +57 -0
- package/dist/server/repositories/WorkflowRepository.js +3 -2
- package/dist/server/triggers/CollectionTrigger.js +3 -2
- package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.d.ts +5 -3
- package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.js +39 -36
- package/dist/server/triggers/ScheduleTrigger/StaticScheduleTrigger.d.ts +4 -2
- package/dist/server/triggers/ScheduleTrigger/StaticScheduleTrigger.js +26 -24
- package/dist/server/triggers/ScheduleTrigger/index.d.ts +2 -1
- package/dist/server/triggers/ScheduleTrigger/index.js +4 -8
- package/dist/server/triggers/index.d.ts +1 -1
- package/dist/server/types/Workflow.d.ts +0 -2
- package/dist/swagger/index.d.ts +0 -14
- package/dist/swagger/index.js +0 -14
- package/package.json +6 -4
- package/dist/client/4d75ef32f02d7285.js +0 -10
- package/dist/client/56ce448358002e64.js +0 -10
- package/dist/client/58bb427e05b600de.js +0 -10
- package/dist/client/739d458621edf81f.js +0 -10
- package/dist/client/nodes/output.d.ts +0 -31
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
var __create = Object.create;
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
11
12
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
15
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
16
|
var __export = (target, all) => {
|
|
15
17
|
for (var name in all)
|
|
@@ -23,110 +25,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
25
|
}
|
|
24
26
|
return to;
|
|
25
27
|
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
26
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
37
|
var workflows_exports = {};
|
|
28
38
|
__export(workflows_exports, {
|
|
29
39
|
default: () => workflows_default
|
|
30
40
|
});
|
|
31
41
|
module.exports = __toCommonJS(workflows_exports);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
dumpRules: "required",
|
|
35
|
-
migrationRules: ["overwrite", "schema-only"],
|
|
36
|
-
name: "workflows",
|
|
37
|
-
shared: true,
|
|
38
|
-
repository: "WorkflowRepository",
|
|
39
|
-
fields: [
|
|
40
|
-
{
|
|
41
|
-
name: "key",
|
|
42
|
-
type: "uid"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
type: "string",
|
|
46
|
-
name: "title",
|
|
47
|
-
interface: "input",
|
|
48
|
-
uiSchema: {
|
|
49
|
-
title: '{{t("Name")}}',
|
|
50
|
-
type: "string",
|
|
51
|
-
"x-component": "Input",
|
|
52
|
-
required: true
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
type: "boolean",
|
|
57
|
-
name: "enabled",
|
|
58
|
-
defaultValue: false
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
type: "text",
|
|
62
|
-
name: "description"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
type: "string",
|
|
66
|
-
name: "type",
|
|
67
|
-
required: true
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
type: "string",
|
|
71
|
-
name: "triggerTitle"
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
type: "jsonb",
|
|
75
|
-
name: "config",
|
|
76
|
-
required: true,
|
|
77
|
-
defaultValue: {}
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
type: "hasMany",
|
|
81
|
-
name: "nodes",
|
|
82
|
-
target: "flow_nodes",
|
|
83
|
-
onDelete: "CASCADE"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
type: "hasMany",
|
|
87
|
-
name: "executions"
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
type: "integer",
|
|
91
|
-
name: "executed",
|
|
92
|
-
defaultValue: 0
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
type: "integer",
|
|
96
|
-
name: "allExecuted",
|
|
97
|
-
defaultValue: 0
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
type: "boolean",
|
|
101
|
-
name: "current"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
type: "boolean",
|
|
105
|
-
name: "sync",
|
|
106
|
-
defaultValue: false
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
type: "hasMany",
|
|
110
|
-
name: "revisions",
|
|
111
|
-
target: "workflows",
|
|
112
|
-
foreignKey: "key",
|
|
113
|
-
sourceKey: "key",
|
|
114
|
-
// NOTE: no constraints needed here because tricky self-referencing
|
|
115
|
-
constraints: false,
|
|
116
|
-
onDelete: "NO ACTION"
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
type: "jsonb",
|
|
120
|
-
name: "options",
|
|
121
|
-
defaultValue: {}
|
|
122
|
-
}
|
|
123
|
-
],
|
|
124
|
-
// NOTE: use unique index for avoiding deadlock in mysql when setCurrent
|
|
125
|
-
indexes: [
|
|
126
|
-
{
|
|
127
|
-
unique: true,
|
|
128
|
-
fields: ["key", "current"]
|
|
129
|
-
}
|
|
130
|
-
]
|
|
131
|
-
};
|
|
132
|
-
}
|
|
42
|
+
var import_workflows = __toESM(require("../../common/collections/workflows"));
|
|
43
|
+
var workflows_default = import_workflows.default;
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
appVersion: string;
|
|
12
|
+
on: string;
|
|
13
|
+
up(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 stats_exports = {};
|
|
28
|
+
__export(stats_exports, {
|
|
29
|
+
default: () => stats_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(stats_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
class stats_default extends import_server.Migration {
|
|
34
|
+
appVersion = "<1.7.0";
|
|
35
|
+
on = "afterLoad";
|
|
36
|
+
async up() {
|
|
37
|
+
const { db } = this.context;
|
|
38
|
+
const WorkflowRepo = db.getRepository("workflows");
|
|
39
|
+
const WorkflowStatsModel = db.getModel("workflowStats");
|
|
40
|
+
const WorkflowVersionStatsModel = db.getModel("workflowVersionStats");
|
|
41
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
42
|
+
const workflows = await WorkflowRepo.find({
|
|
43
|
+
fields: ["id", "key", "executed", "allExecuted"],
|
|
44
|
+
transaction
|
|
45
|
+
});
|
|
46
|
+
const groupCounts = {};
|
|
47
|
+
for (const workflow of workflows) {
|
|
48
|
+
const versionStats = await WorkflowVersionStatsModel.findOne({
|
|
49
|
+
where: {
|
|
50
|
+
id: workflow.id
|
|
51
|
+
},
|
|
52
|
+
transaction
|
|
53
|
+
});
|
|
54
|
+
if (!versionStats) {
|
|
55
|
+
await WorkflowVersionStatsModel.create(
|
|
56
|
+
{
|
|
57
|
+
id: workflow.id,
|
|
58
|
+
executed: workflow.get("executed")
|
|
59
|
+
},
|
|
60
|
+
{ transaction }
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const key = workflow.get("key");
|
|
64
|
+
groupCounts[key] = {
|
|
65
|
+
key,
|
|
66
|
+
executed: workflow.get("allExecuted") || 0
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
for (const values of Object.values(groupCounts)) {
|
|
70
|
+
const stats = await WorkflowStatsModel.findOne({
|
|
71
|
+
where: {
|
|
72
|
+
key: values.key
|
|
73
|
+
},
|
|
74
|
+
transaction
|
|
75
|
+
});
|
|
76
|
+
if (!stats) {
|
|
77
|
+
await WorkflowStatsModel.create(values, { transaction });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { Migration } from '@nocobase/server';
|
|
10
|
+
export default class extends Migration {
|
|
11
|
+
appVersion: string;
|
|
12
|
+
on: string;
|
|
13
|
+
up(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 remove_jobs_auto_increment_exports = {};
|
|
28
|
+
__export(remove_jobs_auto_increment_exports, {
|
|
29
|
+
default: () => remove_jobs_auto_increment_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(remove_jobs_auto_increment_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
class remove_jobs_auto_increment_default extends import_server.Migration {
|
|
34
|
+
appVersion = "<1.7.0";
|
|
35
|
+
on = "beforeLoad";
|
|
36
|
+
async up() {
|
|
37
|
+
const { db } = this.context;
|
|
38
|
+
const jobCollection = db.collection({
|
|
39
|
+
name: "jobs"
|
|
40
|
+
});
|
|
41
|
+
const tableNameWithQuotes = jobCollection.getRealTableName(true);
|
|
42
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
43
|
+
if (this.db.isPostgresCompatibleDialect()) {
|
|
44
|
+
await db.sequelize.query(`ALTER TABLE ${tableNameWithQuotes} ALTER COLUMN id DROP DEFAULT`, {
|
|
45
|
+
transaction
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (this.db.isMySQLCompatibleDialect()) {
|
|
50
|
+
await db.sequelize.query(`ALTER TABLE ${tableNameWithQuotes} MODIFY COLUMN id BIGINT`, {
|
|
51
|
+
transaction
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -49,7 +49,7 @@ class WorkflowRepository extends import_database.Repository {
|
|
|
49
49
|
const origin = await this.findOne({
|
|
50
50
|
filterByTk,
|
|
51
51
|
filter,
|
|
52
|
-
appends: ["nodes"],
|
|
52
|
+
appends: ["nodes", "stats", "versionStats", "categories.id"],
|
|
53
53
|
context,
|
|
54
54
|
transaction
|
|
55
55
|
});
|
|
@@ -58,7 +58,6 @@ class WorkflowRepository extends import_database.Repository {
|
|
|
58
58
|
key: filter.key,
|
|
59
59
|
title: origin.title,
|
|
60
60
|
triggerTitle: origin.triggerTitle,
|
|
61
|
-
allExecuted: origin.allExecuted,
|
|
62
61
|
current: null,
|
|
63
62
|
...values
|
|
64
63
|
} : values;
|
|
@@ -66,6 +65,8 @@ class WorkflowRepository extends import_database.Repository {
|
|
|
66
65
|
values: {
|
|
67
66
|
title: `${origin.title} copy`,
|
|
68
67
|
description: origin.description,
|
|
68
|
+
options: origin.options,
|
|
69
|
+
categories: origin.categories.map((item) => item.id),
|
|
69
70
|
...revisionData,
|
|
70
71
|
sync: origin.sync,
|
|
71
72
|
type: origin.type,
|
|
@@ -67,7 +67,8 @@ function getFieldRawName(collection, name) {
|
|
|
67
67
|
class CollectionTrigger extends import__.default {
|
|
68
68
|
events = /* @__PURE__ */ new Map();
|
|
69
69
|
// async function, should return promise
|
|
70
|
-
static async handler(
|
|
70
|
+
static async handler(workflowId, data, options) {
|
|
71
|
+
const workflow = this.workflow.enabledCache.get(workflowId);
|
|
71
72
|
const { skipWorkflow = false, stack } = options.context ?? {};
|
|
72
73
|
if (skipWorkflow) {
|
|
73
74
|
return;
|
|
@@ -161,7 +162,7 @@ class CollectionTrigger extends import__.default {
|
|
|
161
162
|
const name = getHookId(workflow, `${collection}.${type}`);
|
|
162
163
|
if (mode & key) {
|
|
163
164
|
if (!this.events.has(name)) {
|
|
164
|
-
const listener = this.constructor.handler.bind(this, workflow);
|
|
165
|
+
const listener = this.constructor.handler.bind(this, workflow.id);
|
|
165
166
|
this.events.set(name, listener);
|
|
166
167
|
db.on(event, listener);
|
|
167
168
|
}
|
|
@@ -27,10 +27,12 @@ export default class DateFieldScheduleTrigger {
|
|
|
27
27
|
private timer;
|
|
28
28
|
private cache;
|
|
29
29
|
cacheCycle: number;
|
|
30
|
+
onAfterStart: () => void;
|
|
31
|
+
onBeforeStop: () => void;
|
|
30
32
|
constructor(workflow: Plugin);
|
|
31
|
-
reload():
|
|
32
|
-
inspect(
|
|
33
|
-
loadRecordsToSchedule({ id, config: { collection, limit, startsOn, repeat, endsOn },
|
|
33
|
+
reload(): void;
|
|
34
|
+
inspect(workflow: WorkflowModel): Promise<void>;
|
|
35
|
+
loadRecordsToSchedule({ id, config: { collection, limit, startsOn, repeat, endsOn }, stats }: WorkflowModel, currentDate: Date): Promise<import("@nocobase/database").Model<any, any>[]>;
|
|
34
36
|
getRecordNextTime(workflow: WorkflowModel, record: any, nextSecond?: boolean): any;
|
|
35
37
|
schedule(workflow: WorkflowModel, record: any, nextTime: any, toggle?: boolean, options?: {}): Promise<void>;
|
|
36
38
|
trigger(workflow: WorkflowModel, record: any, nextTime: any, { transaction }?: Transactionable): Promise<void>;
|
|
@@ -99,44 +99,49 @@ function getHookId(workflow, type) {
|
|
|
99
99
|
class DateFieldScheduleTrigger {
|
|
100
100
|
constructor(workflow) {
|
|
101
101
|
this.workflow = workflow;
|
|
102
|
-
workflow.app.on("afterStart",
|
|
103
|
-
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
this.timer = setInterval(() => this.reload(), this.cacheCycle);
|
|
107
|
-
this.reload();
|
|
108
|
-
});
|
|
109
|
-
workflow.app.on("beforeStop", () => {
|
|
110
|
-
if (this.timer) {
|
|
111
|
-
clearInterval(this.timer);
|
|
112
|
-
}
|
|
113
|
-
for (const [key, timer] of this.cache.entries()) {
|
|
114
|
-
clearTimeout(timer);
|
|
115
|
-
this.cache.delete(key);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
102
|
+
workflow.app.on("afterStart", this.onAfterStart);
|
|
103
|
+
workflow.app.on("beforeStop", this.onBeforeStop);
|
|
118
104
|
}
|
|
119
105
|
events = /* @__PURE__ */ new Map();
|
|
120
106
|
timer = null;
|
|
121
107
|
cache = /* @__PURE__ */ new Map();
|
|
122
108
|
// caching workflows in range, default to 5min
|
|
123
109
|
cacheCycle = 3e5;
|
|
124
|
-
|
|
110
|
+
onAfterStart = () => {
|
|
111
|
+
if (this.timer) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.timer = setInterval(() => this.reload(), this.cacheCycle);
|
|
115
|
+
this.reload();
|
|
116
|
+
};
|
|
117
|
+
onBeforeStop = () => {
|
|
118
|
+
if (this.timer) {
|
|
119
|
+
clearInterval(this.timer);
|
|
120
|
+
}
|
|
121
|
+
for (const [key, timer] of this.cache.entries()) {
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
this.cache.delete(key);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
reload() {
|
|
127
|
+
for (const [key, timer] of this.cache.entries()) {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
this.cache.delete(key);
|
|
130
|
+
}
|
|
125
131
|
const workflows = Array.from(this.workflow.enabledCache.values()).filter(
|
|
126
132
|
(item) => item.type === "schedule" && item.config.mode === import_utils.SCHEDULE_MODE.DATE_FIELD
|
|
127
133
|
);
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
workflows.forEach((workflow) => {
|
|
135
|
+
this.inspect(workflow);
|
|
136
|
+
});
|
|
130
137
|
}
|
|
131
|
-
inspect(
|
|
138
|
+
async inspect(workflow) {
|
|
132
139
|
const now = /* @__PURE__ */ new Date();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.schedule(workflow, record, nextTime, Boolean(nextTime));
|
|
139
|
-
});
|
|
140
|
+
const records = await this.loadRecordsToSchedule(workflow, now);
|
|
141
|
+
this.workflow.getLogger(workflow.id).info(`[Schedule on date field] ${records.length} records to schedule`);
|
|
142
|
+
records.forEach((record) => {
|
|
143
|
+
const nextTime = this.getRecordNextTime(workflow, record);
|
|
144
|
+
this.schedule(workflow, record, nextTime, Boolean(nextTime));
|
|
140
145
|
});
|
|
141
146
|
}
|
|
142
147
|
// 1. startsOn in range -> yes
|
|
@@ -146,10 +151,10 @@ class DateFieldScheduleTrigger {
|
|
|
146
151
|
// b. repeat in range (number or cron):
|
|
147
152
|
// i. endsOn after now -> yes
|
|
148
153
|
// ii. endsOn before now -> no
|
|
149
|
-
async loadRecordsToSchedule({ id, config: { collection, limit, startsOn, repeat, endsOn },
|
|
154
|
+
async loadRecordsToSchedule({ id, config: { collection, limit, startsOn, repeat, endsOn }, stats }, currentDate) {
|
|
150
155
|
const { dataSourceManager } = this.workflow.app;
|
|
151
|
-
if (limit &&
|
|
152
|
-
this.workflow.getLogger(id).warn(`[Schedule on date field] limit reached (all executed ${
|
|
156
|
+
if (limit && stats.executed >= limit) {
|
|
157
|
+
this.workflow.getLogger(id).warn(`[Schedule on date field] limit reached (all executed ${stats.executed})`);
|
|
153
158
|
return [];
|
|
154
159
|
}
|
|
155
160
|
if (!startsOn) {
|
|
@@ -210,8 +215,6 @@ class DateFieldScheduleTrigger {
|
|
|
210
215
|
[import_database.Op.gte]: new Date(endTimestamp)
|
|
211
216
|
}
|
|
212
217
|
});
|
|
213
|
-
} else {
|
|
214
|
-
this.workflow.getLogger(id).warn(`[Schedule on date field] "endsOn.field" is not configured`);
|
|
215
218
|
}
|
|
216
219
|
}
|
|
217
220
|
}
|
|
@@ -232,9 +235,9 @@ class DateFieldScheduleTrigger {
|
|
|
232
235
|
getRecordNextTime(workflow, record, nextSecond = false) {
|
|
233
236
|
const {
|
|
234
237
|
config: { startsOn, endsOn, repeat, limit },
|
|
235
|
-
|
|
238
|
+
stats
|
|
236
239
|
} = workflow;
|
|
237
|
-
if (limit &&
|
|
240
|
+
if (limit && stats.executed >= limit) {
|
|
238
241
|
return null;
|
|
239
242
|
}
|
|
240
243
|
const range = this.cacheCycle;
|
|
@@ -324,7 +327,7 @@ class DateFieldScheduleTrigger {
|
|
|
324
327
|
eventKey
|
|
325
328
|
}
|
|
326
329
|
);
|
|
327
|
-
if (!workflow.config.repeat || workflow.config.limit && workflow.
|
|
330
|
+
if (!workflow.config.repeat || workflow.config.limit && workflow.stats.executed >= workflow.config.limit - 1) {
|
|
328
331
|
return;
|
|
329
332
|
}
|
|
330
333
|
const n = this.getRecordNextTime(workflow, data, true);
|
|
@@ -333,7 +336,7 @@ class DateFieldScheduleTrigger {
|
|
|
333
336
|
}
|
|
334
337
|
}
|
|
335
338
|
on(workflow) {
|
|
336
|
-
this.inspect(
|
|
339
|
+
this.inspect(workflow);
|
|
337
340
|
const { collection } = workflow.config;
|
|
338
341
|
const [dataSourceName, collectionName] = (0, import_data_source_manager.parseCollectionName)(collection);
|
|
339
342
|
const event = `${collectionName}.afterSaveWithAssociations`;
|
|
@@ -11,9 +11,11 @@ import { WorkflowModel } from '../../types';
|
|
|
11
11
|
export default class StaticScheduleTrigger {
|
|
12
12
|
workflow: Plugin;
|
|
13
13
|
private timers;
|
|
14
|
+
onAfterStart: () => void;
|
|
15
|
+
onBeforeStop: () => void;
|
|
14
16
|
constructor(workflow: Plugin);
|
|
15
|
-
inspect(
|
|
16
|
-
getNextTime({ config,
|
|
17
|
+
inspect(workflow: WorkflowModel): void;
|
|
18
|
+
getNextTime({ config, stats }: WorkflowModel, currentDate: Date, nextSecond?: boolean): number;
|
|
17
19
|
schedule(workflow: WorkflowModel, nextTime: number, toggle?: boolean): void;
|
|
18
20
|
trigger(workflow: WorkflowModel, time: number): Promise<void>;
|
|
19
21
|
on(workflow: any): void;
|
|
@@ -45,33 +45,35 @@ const MAX_SAFE_INTERVAL = 2147483647;
|
|
|
45
45
|
class StaticScheduleTrigger {
|
|
46
46
|
constructor(workflow) {
|
|
47
47
|
this.workflow = workflow;
|
|
48
|
-
workflow.app.on("afterStart",
|
|
49
|
-
|
|
50
|
-
(item) => item.type === "schedule" && item.config.mode === import_utils.SCHEDULE_MODE.STATIC
|
|
51
|
-
);
|
|
52
|
-
this.inspect(workflows);
|
|
53
|
-
});
|
|
54
|
-
workflow.app.on("beforeStop", () => {
|
|
55
|
-
for (const timer of this.timers.values()) {
|
|
56
|
-
clearInterval(timer);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
48
|
+
workflow.app.on("afterStart", this.onAfterStart);
|
|
49
|
+
workflow.app.on("beforeStop", this.onBeforeStop);
|
|
59
50
|
}
|
|
60
51
|
timers = /* @__PURE__ */ new Map();
|
|
61
|
-
|
|
62
|
-
const
|
|
52
|
+
onAfterStart = () => {
|
|
53
|
+
const workflows = Array.from(this.workflow.enabledCache.values()).filter(
|
|
54
|
+
(item) => item.type === "schedule" && item.config.mode === import_utils.SCHEDULE_MODE.STATIC
|
|
55
|
+
);
|
|
63
56
|
workflows.forEach((workflow) => {
|
|
64
|
-
|
|
65
|
-
if (nextTime) {
|
|
66
|
-
this.workflow.getLogger(workflow.id).info(`caching scheduled workflow will run at: ${new Date(nextTime).toISOString()}`);
|
|
67
|
-
} else {
|
|
68
|
-
this.workflow.getLogger(workflow.id).info("workflow will not be scheduled");
|
|
69
|
-
}
|
|
70
|
-
this.schedule(workflow, nextTime, nextTime >= now.getTime());
|
|
57
|
+
this.inspect(workflow);
|
|
71
58
|
});
|
|
59
|
+
};
|
|
60
|
+
onBeforeStop = () => {
|
|
61
|
+
for (const timer of this.timers.values()) {
|
|
62
|
+
clearInterval(timer);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
inspect(workflow) {
|
|
66
|
+
const now = /* @__PURE__ */ new Date();
|
|
67
|
+
const nextTime = this.getNextTime(workflow, now);
|
|
68
|
+
if (nextTime) {
|
|
69
|
+
this.workflow.getLogger(workflow.id).info(`caching scheduled workflow will run at: ${new Date(nextTime).toISOString()}`);
|
|
70
|
+
} else {
|
|
71
|
+
this.workflow.getLogger(workflow.id).info("workflow will not be scheduled");
|
|
72
|
+
}
|
|
73
|
+
this.schedule(workflow, nextTime, nextTime >= now.getTime());
|
|
72
74
|
}
|
|
73
|
-
getNextTime({ config,
|
|
74
|
-
if (config.limit &&
|
|
75
|
+
getNextTime({ config, stats }, currentDate, nextSecond = false) {
|
|
76
|
+
if (config.limit && stats.executed >= config.limit) {
|
|
75
77
|
return null;
|
|
76
78
|
}
|
|
77
79
|
if (!config.startsOn) {
|
|
@@ -135,7 +137,7 @@ class StaticScheduleTrigger {
|
|
|
135
137
|
const eventKey = `${workflow.id}@${time}`;
|
|
136
138
|
this.timers.delete(eventKey);
|
|
137
139
|
this.workflow.trigger(workflow, { date: new Date(time) }, { eventKey });
|
|
138
|
-
if (!workflow.config.repeat || workflow.config.limit && workflow.
|
|
140
|
+
if (!workflow.config.repeat || workflow.config.limit && workflow.stats.executed >= workflow.config.limit - 1) {
|
|
139
141
|
return;
|
|
140
142
|
}
|
|
141
143
|
const nextTime = this.getNextTime(workflow, /* @__PURE__ */ new Date(), true);
|
|
@@ -144,7 +146,7 @@ class StaticScheduleTrigger {
|
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
on(workflow) {
|
|
147
|
-
this.inspect(
|
|
149
|
+
this.inspect(workflow);
|
|
148
150
|
}
|
|
149
151
|
off(workflow) {
|
|
150
152
|
this.schedule(workflow, null, false);
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import Trigger from '..';
|
|
10
10
|
import type Plugin from '../../Plugin';
|
|
11
|
+
import { WorkflowModel } from '../../types';
|
|
11
12
|
export default class ScheduleTrigger extends Trigger {
|
|
12
13
|
sync: boolean;
|
|
13
14
|
private modes;
|
|
@@ -16,5 +17,5 @@ export default class ScheduleTrigger extends Trigger {
|
|
|
16
17
|
on(workflow: any): void;
|
|
17
18
|
off(workflow: any): void;
|
|
18
19
|
execute(workflow: any, values: any, options: any): Promise<any>;
|
|
19
|
-
validateContext(values: any): any;
|
|
20
|
+
validateContext(values: any, workflow: WorkflowModel): any;
|
|
20
21
|
}
|
|
@@ -88,19 +88,15 @@ class ScheduleTrigger extends import__.default {
|
|
|
88
88
|
// });
|
|
89
89
|
// return !existed.length;
|
|
90
90
|
// }
|
|
91
|
-
validateContext(values) {
|
|
91
|
+
validateContext(values, workflow) {
|
|
92
92
|
var _a;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
mode: "Mode is required"
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
const trigger = this.getTrigger(values.mode);
|
|
93
|
+
const { mode } = workflow.config;
|
|
94
|
+
const trigger = this.getTrigger(mode);
|
|
99
95
|
if (!trigger) {
|
|
100
96
|
return {
|
|
101
97
|
mode: "Mode in invalid"
|
|
102
98
|
};
|
|
103
99
|
}
|
|
104
|
-
return (_a = trigger.validateContext) == null ? void 0 : _a.call(trigger, values);
|
|
100
|
+
return (_a = trigger.validateContext) == null ? void 0 : _a.call(trigger, values, workflow);
|
|
105
101
|
}
|
|
106
102
|
}
|
|
@@ -17,7 +17,7 @@ export declare abstract class Trigger {
|
|
|
17
17
|
off(workflow: WorkflowModel): void;
|
|
18
18
|
validateEvent(workflow: WorkflowModel, context: any, options: Transactionable): boolean | Promise<boolean>;
|
|
19
19
|
duplicateConfig?(workflow: WorkflowModel, options: Transactionable): object | Promise<object>;
|
|
20
|
-
validateContext?(values: any): null | void | {
|
|
20
|
+
validateContext?(values: any, workflow: WorkflowModel): null | void | {
|
|
21
21
|
[key: string]: string;
|
|
22
22
|
};
|
|
23
23
|
sync?: boolean;
|
package/dist/swagger/index.d.ts
CHANGED
|
@@ -553,14 +553,6 @@ declare const _default: {
|
|
|
553
553
|
type: string;
|
|
554
554
|
description: string;
|
|
555
555
|
};
|
|
556
|
-
executed: {
|
|
557
|
-
type: string;
|
|
558
|
-
description: string;
|
|
559
|
-
};
|
|
560
|
-
allExecuted: {
|
|
561
|
-
type: string;
|
|
562
|
-
description: string;
|
|
563
|
-
};
|
|
564
556
|
};
|
|
565
557
|
};
|
|
566
558
|
filterByTk: {
|
|
@@ -597,12 +589,6 @@ declare const _default: {
|
|
|
597
589
|
key: {
|
|
598
590
|
$ref: string;
|
|
599
591
|
};
|
|
600
|
-
executed: {
|
|
601
|
-
$ref: string;
|
|
602
|
-
};
|
|
603
|
-
allExecuted: {
|
|
604
|
-
$ref: string;
|
|
605
|
-
};
|
|
606
592
|
};
|
|
607
593
|
};
|
|
608
594
|
};
|