@nocobase/plugin-workflow 0.17.0-alpha.7 → 0.18.0-alpha.8
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/index.d.ts +8 -0
- package/dist/client/index.js +30 -30
- package/dist/client/nodes/calculation.d.ts +7 -2
- package/dist/client/nodes/index.d.ts +10 -5
- package/dist/client/triggers/collection.d.ts +0 -1
- package/dist/client/triggers/index.d.ts +2 -3
- package/dist/client/triggers/schedule/index.d.ts +0 -1
- package/dist/client/variable.d.ts +15 -14
- package/dist/externalVersion.js +17 -16
- package/dist/locale/en-US.json +1 -1
- package/dist/locale/es-ES.json +1 -1
- package/dist/locale/fr-FR.json +1 -1
- package/dist/locale/pt-BR.json +1 -1
- package/dist/locale/zh-CN.json +3 -1
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/server/Plugin.d.ts +10 -11
- package/dist/server/Plugin.js +105 -69
- package/dist/server/Processor.d.ts +9 -5
- package/dist/server/Processor.js +10 -35
- package/dist/server/actions/workflows.js +4 -4
- package/dist/server/collections/executions.js +0 -5
- package/dist/server/collections/workflows.js +0 -5
- package/dist/server/constants.d.ts +17 -22
- package/dist/server/constants.js +0 -7
- package/dist/server/instructions/CalculationInstruction.d.ts +4 -2
- package/dist/server/instructions/CalculationInstruction.js +2 -10
- package/dist/server/instructions/ConditionInstruction.d.ts +10 -2
- package/dist/server/instructions/ConditionInstruction.js +7 -0
- package/dist/server/instructions/CreateInstruction.d.ts +1 -1
- package/dist/server/instructions/CreateInstruction.js +4 -4
- package/dist/server/instructions/DestroyInstruction.d.ts +1 -1
- package/dist/server/instructions/DestroyInstruction.js +2 -2
- package/dist/server/instructions/QueryInstruction.d.ts +4 -1
- package/dist/server/instructions/QueryInstruction.js +2 -2
- package/dist/server/instructions/UpdateInstruction.d.ts +1 -1
- package/dist/server/instructions/UpdateInstruction.js +2 -2
- package/dist/server/instructions/index.d.ts +9 -6
- package/dist/server/instructions/index.js +2 -2
- package/dist/server/migrations/20230612021134-manual-collection-block.js +1 -0
- package/dist/server/triggers/CollectionTrigger.js +3 -3
- package/dist/server/triggers/ScheduleTrigger.d.ts +1 -1
- package/dist/server/triggers/ScheduleTrigger.js +14 -14
- package/dist/server/triggers/index.d.ts +2 -2
- package/dist/server/triggers/index.js +2 -2
- package/dist/server/types/Execution.d.ts +0 -2
- package/dist/server/types/Workflow.d.ts +0 -1
- package/package.json +6 -5
package/dist/server/Processor.js
CHANGED
|
@@ -41,7 +41,6 @@ class Processor {
|
|
|
41
41
|
[import_constants.JOB_STATUS.RETRY_NEEDED]: import_constants.EXECUTION_STATUS.RETRY_NEEDED
|
|
42
42
|
};
|
|
43
43
|
logger;
|
|
44
|
-
transaction;
|
|
45
44
|
nodes = [];
|
|
46
45
|
nodesMap = /* @__PURE__ */ new Map();
|
|
47
46
|
jobsMap = /* @__PURE__ */ new Map();
|
|
@@ -68,33 +67,22 @@ class Processor {
|
|
|
68
67
|
this.jobsMapByNodeKey[node.key] = job.result;
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
|
-
async getTransaction() {
|
|
72
|
-
var _a;
|
|
73
|
-
if (!((_a = this.execution.workflow.options) == null ? void 0 : _a.useTransaction)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const { options } = this;
|
|
77
|
-
return options.transaction && !options.transaction.finished ? options.transaction : await options.plugin.db.sequelize.transaction();
|
|
78
|
-
}
|
|
79
70
|
async prepare() {
|
|
80
71
|
const { execution } = this;
|
|
81
72
|
if (!execution.workflow) {
|
|
82
73
|
execution.workflow = await execution.getWorkflow();
|
|
83
74
|
}
|
|
84
|
-
const transaction = await this.getTransaction();
|
|
85
|
-
this.transaction = transaction;
|
|
86
75
|
const nodes = await execution.workflow.getNodes();
|
|
87
76
|
this.makeNodes(nodes);
|
|
88
77
|
const jobs = await execution.getJobs({
|
|
89
|
-
order: [["id", "ASC"]]
|
|
90
|
-
transaction
|
|
78
|
+
order: [["id", "ASC"]]
|
|
91
79
|
});
|
|
92
80
|
this.makeJobs(jobs);
|
|
93
81
|
}
|
|
94
82
|
async start() {
|
|
95
83
|
const { execution } = this;
|
|
96
84
|
if (execution.status !== import_constants.EXECUTION_STATUS.STARTED) {
|
|
97
|
-
throw new Error(`execution was ended with status ${execution.status}`);
|
|
85
|
+
throw new Error(`execution was ended with status ${execution.status} before, could not be started again`);
|
|
98
86
|
}
|
|
99
87
|
await this.prepare();
|
|
100
88
|
if (this.nodes.length) {
|
|
@@ -107,17 +95,12 @@ class Processor {
|
|
|
107
95
|
async resume(job) {
|
|
108
96
|
const { execution } = this;
|
|
109
97
|
if (execution.status !== import_constants.EXECUTION_STATUS.STARTED) {
|
|
110
|
-
throw new Error(`execution was ended with status ${execution.status}`);
|
|
98
|
+
throw new Error(`execution was ended with status ${execution.status} before, could not be resumed`);
|
|
111
99
|
}
|
|
112
100
|
await this.prepare();
|
|
113
101
|
const node = this.nodesMap.get(job.nodeId);
|
|
114
102
|
await this.recall(node, job);
|
|
115
103
|
}
|
|
116
|
-
async commit() {
|
|
117
|
-
if (this.transaction && (!this.options.transaction || this.options.transaction.finished)) {
|
|
118
|
-
await this.transaction.commit();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
104
|
async exec(instruction, node, prevJob) {
|
|
122
105
|
let job;
|
|
123
106
|
try {
|
|
@@ -188,10 +171,9 @@ class Processor {
|
|
|
188
171
|
async exit(s) {
|
|
189
172
|
if (typeof s === "number") {
|
|
190
173
|
const status = this.constructor.StatusMap[s] ?? Math.sign(s);
|
|
191
|
-
await this.execution.update({ status }
|
|
174
|
+
await this.execution.update({ status });
|
|
192
175
|
}
|
|
193
176
|
this.logger.info(`execution (${this.execution.id}) exiting with status ${this.execution.status}`);
|
|
194
|
-
await this.commit();
|
|
195
177
|
return null;
|
|
196
178
|
}
|
|
197
179
|
// TODO(optimize)
|
|
@@ -200,22 +182,15 @@ class Processor {
|
|
|
200
182
|
const { model } = database.getCollection("jobs");
|
|
201
183
|
let job;
|
|
202
184
|
if (payload instanceof model) {
|
|
203
|
-
job = await payload.save(
|
|
185
|
+
job = await payload.save();
|
|
204
186
|
} else if (payload.id) {
|
|
205
187
|
job = await model.findByPk(payload.id);
|
|
206
|
-
await job.update(payload
|
|
207
|
-
transaction: this.transaction
|
|
208
|
-
});
|
|
188
|
+
await job.update(payload);
|
|
209
189
|
} else {
|
|
210
|
-
job = await model.create(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
transaction: this.transaction
|
|
217
|
-
}
|
|
218
|
-
);
|
|
190
|
+
job = await model.create({
|
|
191
|
+
...payload,
|
|
192
|
+
executionId: this.execution.id
|
|
193
|
+
});
|
|
219
194
|
}
|
|
220
195
|
this.jobsMap.set(job.id, job);
|
|
221
196
|
const node = this.nodesMap.get(job.nodeId);
|
|
@@ -36,6 +36,7 @@ __export(workflows_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(workflows_exports);
|
|
37
37
|
var import_actions = __toESM(require("@nocobase/actions"));
|
|
38
38
|
var import_database = require("@nocobase/database");
|
|
39
|
+
var import_Plugin = __toESM(require("../Plugin"));
|
|
39
40
|
async function update(context, next) {
|
|
40
41
|
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
41
42
|
const { filterByTk, values } = context.action.params;
|
|
@@ -80,11 +81,10 @@ async function destroy(context, next) {
|
|
|
80
81
|
next();
|
|
81
82
|
}
|
|
82
83
|
async function revision(context, next) {
|
|
83
|
-
const plugin = context.app.getPlugin(
|
|
84
|
-
const { db } = context;
|
|
84
|
+
const plugin = context.app.getPlugin(import_Plugin.default);
|
|
85
85
|
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
86
86
|
const { filterByTk, filter = {}, values = {} } = context.action.params;
|
|
87
|
-
context.body = await db.sequelize.transaction(async (transaction) => {
|
|
87
|
+
context.body = await context.db.sequelize.transaction(async (transaction) => {
|
|
88
88
|
const origin = await repository.findOne({
|
|
89
89
|
filterByTk,
|
|
90
90
|
filter,
|
|
@@ -146,7 +146,7 @@ async function revision(context, next) {
|
|
|
146
146
|
await next();
|
|
147
147
|
}
|
|
148
148
|
async function sync(context, next) {
|
|
149
|
-
const plugin = context.app.getPlugin(
|
|
149
|
+
const plugin = context.app.getPlugin(import_Plugin.default);
|
|
150
150
|
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
151
151
|
const { filterByTk, filter = {} } = context.action.params;
|
|
152
152
|
const workflows = await repository.find({
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
export declare const EXECUTION_STATUS: {
|
|
2
|
-
QUEUEING: any;
|
|
3
|
-
STARTED:
|
|
4
|
-
RESOLVED:
|
|
5
|
-
FAILED:
|
|
6
|
-
ERROR:
|
|
7
|
-
ABORTED:
|
|
8
|
-
CANCELED:
|
|
9
|
-
REJECTED:
|
|
10
|
-
RETRY_NEEDED:
|
|
2
|
+
readonly QUEUEING: any;
|
|
3
|
+
readonly STARTED: 0;
|
|
4
|
+
readonly RESOLVED: 1;
|
|
5
|
+
readonly FAILED: -1;
|
|
6
|
+
readonly ERROR: -2;
|
|
7
|
+
readonly ABORTED: -3;
|
|
8
|
+
readonly CANCELED: -4;
|
|
9
|
+
readonly REJECTED: -5;
|
|
10
|
+
readonly RETRY_NEEDED: -6;
|
|
11
11
|
};
|
|
12
12
|
export declare const JOB_STATUS: {
|
|
13
|
-
PENDING:
|
|
14
|
-
RESOLVED:
|
|
15
|
-
FAILED:
|
|
16
|
-
ERROR:
|
|
17
|
-
ABORTED:
|
|
18
|
-
CANCELED:
|
|
19
|
-
REJECTED:
|
|
20
|
-
RETRY_NEEDED:
|
|
21
|
-
};
|
|
22
|
-
export declare const BRANCH_INDEX: {
|
|
23
|
-
DEFAULT: any;
|
|
24
|
-
ON_TRUE: number;
|
|
25
|
-
ON_FALSE: number;
|
|
13
|
+
readonly PENDING: 0;
|
|
14
|
+
readonly RESOLVED: 1;
|
|
15
|
+
readonly FAILED: -1;
|
|
16
|
+
readonly ERROR: -2;
|
|
17
|
+
readonly ABORTED: -3;
|
|
18
|
+
readonly CANCELED: -4;
|
|
19
|
+
readonly REJECTED: -5;
|
|
20
|
+
readonly RETRY_NEEDED: -6;
|
|
26
21
|
};
|
package/dist/server/constants.js
CHANGED
|
@@ -17,7 +17,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var constants_exports = {};
|
|
19
19
|
__export(constants_exports, {
|
|
20
|
-
BRANCH_INDEX: () => BRANCH_INDEX,
|
|
21
20
|
EXECUTION_STATUS: () => EXECUTION_STATUS,
|
|
22
21
|
JOB_STATUS: () => JOB_STATUS
|
|
23
22
|
});
|
|
@@ -43,14 +42,8 @@ const JOB_STATUS = {
|
|
|
43
42
|
REJECTED: -5,
|
|
44
43
|
RETRY_NEEDED: -6
|
|
45
44
|
};
|
|
46
|
-
const BRANCH_INDEX = {
|
|
47
|
-
DEFAULT: null,
|
|
48
|
-
ON_TRUE: 1,
|
|
49
|
-
ON_FALSE: 0
|
|
50
|
-
};
|
|
51
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
46
|
0 && (module.exports = {
|
|
53
|
-
BRANCH_INDEX,
|
|
54
47
|
EXECUTION_STATUS,
|
|
55
48
|
JOB_STATUS
|
|
56
49
|
});
|
|
@@ -2,14 +2,16 @@ import { Instruction } from '.';
|
|
|
2
2
|
import type Processor from '../Processor';
|
|
3
3
|
import type { FlowNodeModel } from '../types';
|
|
4
4
|
export interface CalculationConfig {
|
|
5
|
-
dynamic?: boolean | string;
|
|
6
5
|
engine?: string;
|
|
7
6
|
expression?: string;
|
|
8
7
|
}
|
|
9
8
|
export declare class CalculationInstruction extends Instruction {
|
|
10
9
|
run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
|
|
11
10
|
result: any;
|
|
12
|
-
status:
|
|
11
|
+
status: 1;
|
|
12
|
+
} | {
|
|
13
|
+
result: any;
|
|
14
|
+
status: -2;
|
|
13
15
|
}>;
|
|
14
16
|
}
|
|
15
17
|
export default CalculationInstruction;
|
|
@@ -22,20 +22,12 @@ __export(CalculationInstruction_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(CalculationInstruction_exports);
|
|
24
24
|
var import_evaluators = require("@nocobase/evaluators");
|
|
25
|
-
var import_utils = require("@nocobase/utils");
|
|
26
25
|
var import__ = require(".");
|
|
27
26
|
var import_constants = require("../constants");
|
|
28
27
|
class CalculationInstruction extends import__.Instruction {
|
|
29
28
|
async run(node, prevJob, processor) {
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
let scope = processor.getScope(node.id);
|
|
33
|
-
if (dynamic) {
|
|
34
|
-
const parsed = (0, import_utils.parse)(dynamic)(scope) ?? {};
|
|
35
|
-
engine = parsed.engine;
|
|
36
|
-
expression = parsed.expression;
|
|
37
|
-
scope = (0, import_utils.parse)(node.config.scope ?? "")(scope) ?? {};
|
|
38
|
-
}
|
|
29
|
+
const { engine = "math.js", expression = "" } = node.config;
|
|
30
|
+
const scope = processor.getScope(node.id);
|
|
39
31
|
const evaluator = import_evaluators.evaluators.get(engine);
|
|
40
32
|
try {
|
|
41
33
|
const result = evaluator && expression ? evaluator(expression, scope) : null;
|
|
@@ -3,16 +3,24 @@ import { Instruction } from '.';
|
|
|
3
3
|
import type Processor from '../Processor';
|
|
4
4
|
import type { FlowNodeModel, JobModel } from '../types';
|
|
5
5
|
type Comparer = (a: any, b: any) => boolean;
|
|
6
|
+
export declare const BRANCH_INDEX: {
|
|
7
|
+
readonly DEFAULT: any;
|
|
8
|
+
readonly ON_TRUE: 1;
|
|
9
|
+
readonly ON_FALSE: 0;
|
|
10
|
+
};
|
|
6
11
|
export declare const calculators: Registry<Comparer>;
|
|
7
12
|
export declare class ConditionInstruction extends Instruction {
|
|
8
13
|
run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
|
|
9
|
-
status:
|
|
14
|
+
status: 1;
|
|
10
15
|
result: boolean;
|
|
11
16
|
nodeId: number;
|
|
12
17
|
upstreamId: any;
|
|
13
18
|
} | {
|
|
14
19
|
result: any;
|
|
15
|
-
status:
|
|
20
|
+
status: -2;
|
|
21
|
+
} | {
|
|
22
|
+
status: -1;
|
|
23
|
+
result: boolean;
|
|
16
24
|
}>;
|
|
17
25
|
resume(node: FlowNodeModel, branchJob: JobModel, processor: Processor): Promise<any>;
|
|
18
26
|
}
|
|
@@ -17,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var ConditionInstruction_exports = {};
|
|
19
19
|
__export(ConditionInstruction_exports, {
|
|
20
|
+
BRANCH_INDEX: () => BRANCH_INDEX,
|
|
20
21
|
ConditionInstruction: () => ConditionInstruction,
|
|
21
22
|
calculators: () => calculators,
|
|
22
23
|
default: () => ConditionInstruction_default
|
|
@@ -26,6 +27,11 @@ var import_evaluators = require("@nocobase/evaluators");
|
|
|
26
27
|
var import_utils = require("@nocobase/utils");
|
|
27
28
|
var import__ = require(".");
|
|
28
29
|
var import_constants = require("../constants");
|
|
30
|
+
const BRANCH_INDEX = {
|
|
31
|
+
DEFAULT: null,
|
|
32
|
+
ON_TRUE: 1,
|
|
33
|
+
ON_FALSE: 0
|
|
34
|
+
};
|
|
29
35
|
const calculators = new import_utils.Registry();
|
|
30
36
|
function equal(a, b) {
|
|
31
37
|
return a == b;
|
|
@@ -145,6 +151,7 @@ class ConditionInstruction extends import__.Instruction {
|
|
|
145
151
|
var ConditionInstruction_default = ConditionInstruction;
|
|
146
152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
147
153
|
0 && (module.exports = {
|
|
154
|
+
BRANCH_INDEX,
|
|
148
155
|
ConditionInstruction,
|
|
149
156
|
calculators
|
|
150
157
|
});
|
|
@@ -33,8 +33,8 @@ class CreateInstruction extends import__.Instruction {
|
|
|
33
33
|
...options,
|
|
34
34
|
context: {
|
|
35
35
|
executionId: processor.execution.id
|
|
36
|
-
}
|
|
37
|
-
transaction: processor.transaction
|
|
36
|
+
}
|
|
37
|
+
// transaction: processor.transaction,
|
|
38
38
|
});
|
|
39
39
|
let result = created;
|
|
40
40
|
if (created && appends.length) {
|
|
@@ -45,8 +45,8 @@ class CreateInstruction extends import__.Instruction {
|
|
|
45
45
|
}, /* @__PURE__ */ new Set());
|
|
46
46
|
result = await repository.findOne({
|
|
47
47
|
filterByTk: created[model.primaryKeyAttribute],
|
|
48
|
-
appends: Array.from(includeFields)
|
|
49
|
-
transaction: processor.transaction
|
|
48
|
+
appends: Array.from(includeFields)
|
|
49
|
+
// transaction: processor.transaction,
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
return {
|
|
@@ -4,7 +4,7 @@ import type { FlowNodeModel } from '../types';
|
|
|
4
4
|
export declare class DestroyInstruction extends Instruction {
|
|
5
5
|
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
6
6
|
result: any;
|
|
7
|
-
status:
|
|
7
|
+
status: 1;
|
|
8
8
|
}>;
|
|
9
9
|
}
|
|
10
10
|
export default DestroyInstruction;
|
|
@@ -4,7 +4,10 @@ import { Instruction } from '.';
|
|
|
4
4
|
export declare class QueryInstruction extends Instruction {
|
|
5
5
|
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
6
6
|
result: any;
|
|
7
|
-
status:
|
|
7
|
+
status: -1;
|
|
8
|
+
} | {
|
|
9
|
+
result: object;
|
|
10
|
+
status: 1;
|
|
8
11
|
}>;
|
|
9
12
|
}
|
|
10
13
|
export default QueryInstruction;
|
|
@@ -49,8 +49,8 @@ class QueryInstruction extends import__.Instruction {
|
|
|
49
49
|
var _a;
|
|
50
50
|
return `${((_a = item.direction) == null ? void 0 : _a.toLowerCase()) === "desc" ? "-" : ""}${item.field}`;
|
|
51
51
|
}),
|
|
52
|
-
appends
|
|
53
|
-
transaction: processor.transaction
|
|
52
|
+
appends
|
|
53
|
+
// transaction: processor.transaction,
|
|
54
54
|
});
|
|
55
55
|
if (failOnEmpty && (multiple ? !result.length : !result)) {
|
|
56
56
|
return {
|
|
@@ -32,8 +32,8 @@ class UpdateInstruction extends import__.Instruction {
|
|
|
32
32
|
...options,
|
|
33
33
|
context: {
|
|
34
34
|
executionId: processor.execution.id
|
|
35
|
-
}
|
|
36
|
-
transaction: processor.transaction
|
|
35
|
+
}
|
|
36
|
+
// transaction: processor.transaction,
|
|
37
37
|
});
|
|
38
38
|
return {
|
|
39
39
|
result: result.length ?? result,
|
|
@@ -9,12 +9,15 @@ export interface IJob {
|
|
|
9
9
|
}
|
|
10
10
|
export type InstructionResult = IJob | Promise<IJob> | null;
|
|
11
11
|
export type Runner = (node: FlowNodeModel, input: any, processor: Processor) => InstructionResult;
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export type InstructionInterface = {
|
|
13
|
+
run: Runner;
|
|
14
|
+
resume?: Runner;
|
|
15
|
+
getScope?: (node: FlowNodeModel, data: any, processor: Processor) => any;
|
|
16
|
+
duplicateConfig?: (node: FlowNodeModel, options: Transactionable) => object | Promise<object>;
|
|
17
|
+
};
|
|
18
|
+
export declare abstract class Instruction implements InstructionInterface {
|
|
19
|
+
workflow: Plugin;
|
|
20
|
+
constructor(workflow: Plugin);
|
|
15
21
|
abstract run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
|
|
16
|
-
resume?(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
|
|
17
|
-
getScope?(node: FlowNodeModel, data: any, processor: Processor): any;
|
|
18
|
-
duplicateConfig?(node: FlowNodeModel, options: Transactionable): object | Promise<object>;
|
|
19
22
|
}
|
|
20
23
|
export default Instruction;
|
|
@@ -22,8 +22,8 @@ __export(instructions_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(instructions_exports);
|
|
24
24
|
class Instruction {
|
|
25
|
-
constructor(
|
|
26
|
-
this.
|
|
25
|
+
constructor(workflow) {
|
|
26
|
+
this.workflow = workflow;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
var instructions_default = Instruction;
|
|
@@ -113,6 +113,7 @@ class manual_collection_block_default extends import_server.Migration {
|
|
|
113
113
|
}
|
|
114
114
|
const { db } = this.context;
|
|
115
115
|
const NodeRepo = db.getRepository("flow_nodes");
|
|
116
|
+
await NodeRepo.collection.sync();
|
|
116
117
|
await db.sequelize.transaction(async (transaction) => {
|
|
117
118
|
const nodes = await NodeRepo.find({
|
|
118
119
|
filter: {
|
|
@@ -86,7 +86,7 @@ async function handler(workflow, data, options) {
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
const json = (0, import_utils.toJSON)(result);
|
|
89
|
-
this.
|
|
89
|
+
this.workflow.trigger(
|
|
90
90
|
workflow,
|
|
91
91
|
{ data: json },
|
|
92
92
|
{
|
|
@@ -97,7 +97,7 @@ async function handler(workflow, data, options) {
|
|
|
97
97
|
class CollectionTrigger extends import__.default {
|
|
98
98
|
events = /* @__PURE__ */ new Map();
|
|
99
99
|
on(workflow) {
|
|
100
|
-
const { db } = this.
|
|
100
|
+
const { db } = this.workflow.app;
|
|
101
101
|
const { collection, mode } = workflow.config;
|
|
102
102
|
const Collection2 = db.getCollection(collection);
|
|
103
103
|
if (!Collection2) {
|
|
@@ -122,7 +122,7 @@ class CollectionTrigger extends import__.default {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
off(workflow) {
|
|
125
|
-
const { db } = this.
|
|
125
|
+
const { db } = this.workflow.app;
|
|
126
126
|
const { collection, mode } = workflow.config;
|
|
127
127
|
const Collection2 = db.getCollection(collection);
|
|
128
128
|
if (!Collection2) {
|
|
@@ -94,7 +94,7 @@ ScheduleModes.set(SCHEDULE_MODE.CONSTANT, {
|
|
|
94
94
|
return 0;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
this.
|
|
97
|
+
this.workflow.trigger(workflow, { date: now });
|
|
98
98
|
return 1;
|
|
99
99
|
}
|
|
100
100
|
});
|
|
@@ -178,7 +178,7 @@ ScheduleModes.set(SCHEDULE_MODE.COLLECTION_FIELD, {
|
|
|
178
178
|
this.setCache(workflow);
|
|
179
179
|
};
|
|
180
180
|
this.events.set(name, listener);
|
|
181
|
-
this.
|
|
181
|
+
this.workflow.app.db.on(event, listener);
|
|
182
182
|
},
|
|
183
183
|
off(workflow) {
|
|
184
184
|
const { collection } = workflow.config;
|
|
@@ -187,11 +187,11 @@ ScheduleModes.set(SCHEDULE_MODE.COLLECTION_FIELD, {
|
|
|
187
187
|
if (this.events.has(name)) {
|
|
188
188
|
const listener = this.events.get(name);
|
|
189
189
|
this.events.delete(name);
|
|
190
|
-
this.
|
|
190
|
+
this.workflow.app.db.off(event, listener);
|
|
191
191
|
}
|
|
192
192
|
},
|
|
193
193
|
async shouldCache(workflow, now) {
|
|
194
|
-
const { db } = this.
|
|
194
|
+
const { db } = this.workflow.app;
|
|
195
195
|
const { startsOn, endsOn, repeat, collection } = workflow.config;
|
|
196
196
|
const timestamp = now.getTime();
|
|
197
197
|
const startTimestamp = getOnTimestampWithOffset(startsOn, now);
|
|
@@ -265,7 +265,7 @@ ScheduleModes.set(SCHEDULE_MODE.COLLECTION_FIELD, {
|
|
|
265
265
|
[import_database.Op.lt]: new Date(startTimestamp)
|
|
266
266
|
}
|
|
267
267
|
});
|
|
268
|
-
const tsFn = DialectTimestampFnMap[this.
|
|
268
|
+
const tsFn = DialectTimestampFnMap[this.workflow.app.db.options.dialect];
|
|
269
269
|
if (typeof repeat === "number" && tsFn) {
|
|
270
270
|
const modExp = (0, import_database.fn)(
|
|
271
271
|
"MOD",
|
|
@@ -298,7 +298,7 @@ ScheduleModes.set(SCHEDULE_MODE.COLLECTION_FIELD, {
|
|
|
298
298
|
}
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
|
-
const repo = this.
|
|
301
|
+
const repo = this.workflow.app.db.getRepository(collection);
|
|
302
302
|
const instances = await repo.find({
|
|
303
303
|
where: {
|
|
304
304
|
[import_database.Op.and]: conditions
|
|
@@ -309,7 +309,7 @@ ScheduleModes.set(SCHEDULE_MODE.COLLECTION_FIELD, {
|
|
|
309
309
|
} : {}
|
|
310
310
|
});
|
|
311
311
|
instances.forEach((item) => {
|
|
312
|
-
this.
|
|
312
|
+
this.workflow.trigger(workflow, {
|
|
313
313
|
date: now,
|
|
314
314
|
data: item.toJSON()
|
|
315
315
|
});
|
|
@@ -358,9 +358,9 @@ class ScheduleTrigger extends import__.default {
|
|
|
358
358
|
interval = 1e3;
|
|
359
359
|
// caching workflows in range, default to 1min
|
|
360
360
|
cacheCycle = 6e4;
|
|
361
|
-
constructor(
|
|
362
|
-
super(
|
|
363
|
-
|
|
361
|
+
constructor(workflow) {
|
|
362
|
+
super(workflow);
|
|
363
|
+
workflow.app.on("beforeStop", () => {
|
|
364
364
|
if (this.timer) {
|
|
365
365
|
clearInterval(this.timer);
|
|
366
366
|
}
|
|
@@ -368,7 +368,7 @@ class ScheduleTrigger extends import__.default {
|
|
|
368
368
|
}
|
|
369
369
|
init() {
|
|
370
370
|
var _a;
|
|
371
|
-
if (((_a = this.
|
|
371
|
+
if (((_a = this.workflow.app.getPlugin("multi-app-share-collection")) == null ? void 0 : _a.enabled) && this.workflow.app.name !== "main") {
|
|
372
372
|
return;
|
|
373
373
|
}
|
|
374
374
|
if (this.timer) {
|
|
@@ -395,7 +395,7 @@ class ScheduleTrigger extends import__.default {
|
|
|
395
395
|
this.timer = setTimeout(this.run, nextInterval);
|
|
396
396
|
};
|
|
397
397
|
async onTick(now) {
|
|
398
|
-
const isSqlite = this.
|
|
398
|
+
const isSqlite = this.workflow.app.db.options.dialect === "sqlite";
|
|
399
399
|
return Array.from(this.cache.values()).reduce(
|
|
400
400
|
(prev, workflow) => {
|
|
401
401
|
if (!this.shouldTrigger(workflow, now)) {
|
|
@@ -411,7 +411,7 @@ class ScheduleTrigger extends import__.default {
|
|
|
411
411
|
);
|
|
412
412
|
}
|
|
413
413
|
async reload() {
|
|
414
|
-
const WorkflowRepo = this.
|
|
414
|
+
const WorkflowRepo = this.workflow.app.db.getRepository("workflows");
|
|
415
415
|
const workflows = await WorkflowRepo.find({
|
|
416
416
|
filter: { enabled: true, type: "schedule" }
|
|
417
417
|
});
|
|
@@ -424,7 +424,7 @@ class ScheduleTrigger extends import__.default {
|
|
|
424
424
|
workflows.forEach(async (workflow) => {
|
|
425
425
|
const should = await this.shouldCache(workflow, now);
|
|
426
426
|
if (should) {
|
|
427
|
-
this.
|
|
427
|
+
this.workflow.getLogger(workflow.id).info("caching scheduled workflow will run in next minute");
|
|
428
428
|
}
|
|
429
429
|
this.setCache(workflow, !should);
|
|
430
430
|
});
|
|
@@ -2,8 +2,8 @@ import { Transactionable } from '@nocobase/database';
|
|
|
2
2
|
import type Plugin from '../Plugin';
|
|
3
3
|
import type { WorkflowModel } from '../types';
|
|
4
4
|
export declare abstract class Trigger {
|
|
5
|
-
readonly
|
|
6
|
-
constructor(
|
|
5
|
+
readonly workflow: Plugin;
|
|
6
|
+
constructor(workflow: Plugin);
|
|
7
7
|
abstract on(workflow: WorkflowModel): void;
|
|
8
8
|
abstract off(workflow: WorkflowModel): void;
|
|
9
9
|
duplicateConfig?(workflow: WorkflowModel, options: Transactionable): object | Promise<object>;
|
|
@@ -22,8 +22,8 @@ __export(triggers_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(triggers_exports);
|
|
24
24
|
class Trigger {
|
|
25
|
-
constructor(
|
|
26
|
-
this.
|
|
25
|
+
constructor(workflow) {
|
|
26
|
+
this.workflow = workflow;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
var triggers_default = Trigger;
|