@nocobase/plugin-workflow 0.7.0-alpha.83 → 0.7.1-alpha.5
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/lib/Plugin.d.ts +18 -0
- package/lib/Plugin.js +285 -0
- package/lib/Processor.d.ts +40 -0
- package/lib/Processor.js +440 -0
- package/lib/actions/workflows.d.ts +1 -2
- package/lib/actions/workflows.js +13 -87
- package/lib/calculators/index.d.ts +2 -2
- package/lib/calculators/index.js +4 -4
- package/lib/collections/executions.js +7 -15
- package/lib/collections/jobs.js +7 -26
- package/lib/collections/workflows.d.ts +1 -2
- package/lib/collections/workflows.js +67 -67
- package/lib/index.d.ts +4 -3
- package/lib/index.js +24 -10
- package/lib/instructions/calculation.d.ts +1 -1
- package/lib/instructions/calculation.js +4 -6
- package/lib/instructions/condition.d.ts +2 -2
- package/lib/instructions/condition.js +15 -19
- package/lib/instructions/create.d.ts +1 -1
- package/lib/instructions/create.js +8 -12
- package/lib/instructions/delay.d.ts +14 -0
- package/lib/instructions/delay.js +138 -0
- package/lib/instructions/destroy.d.ts +1 -1
- package/lib/instructions/destroy.js +8 -12
- package/lib/instructions/index.d.ts +11 -8
- package/lib/instructions/index.js +43 -13
- package/lib/instructions/parallel.d.ts +3 -3
- package/lib/instructions/parallel.js +15 -19
- package/lib/instructions/prompt.d.ts +2 -2
- package/lib/instructions/prompt.js +2 -2
- package/lib/instructions/query.d.ts +2 -1
- package/lib/instructions/query.js +9 -13
- package/lib/instructions/update.d.ts +2 -2
- package/lib/instructions/update.js +10 -14
- package/lib/models/Execution.d.ts +2 -33
- package/lib/models/Execution.js +2 -397
- package/lib/models/Workflow.d.ts +2 -2
- package/lib/models/Workflow.js +1 -81
- package/lib/triggers/collection.d.ts +2 -6
- package/lib/triggers/collection.js +62 -27
- package/lib/triggers/index.d.ts +11 -4
- package/lib/triggers/index.js +52 -5
- package/lib/triggers/schedule.d.ts +4 -7
- package/lib/triggers/schedule.js +205 -135
- package/package.json +8 -9
- package/lib/server.d.ts +0 -10
- package/lib/server.js +0 -124
package/lib/collections/jobs.js
CHANGED
|
@@ -6,42 +6,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _default = {
|
|
8
8
|
name: 'jobs',
|
|
9
|
-
title: '流程记录',
|
|
10
9
|
fields: [{
|
|
11
|
-
interface: 'linkTo',
|
|
12
10
|
type: 'belongsTo',
|
|
13
|
-
name: 'execution'
|
|
14
|
-
title: '所属流程'
|
|
11
|
+
name: 'execution'
|
|
15
12
|
}, {
|
|
16
|
-
interface: 'linkTo',
|
|
17
13
|
type: 'belongsTo',
|
|
18
14
|
name: 'node',
|
|
19
|
-
target: 'flow_nodes'
|
|
20
|
-
title: '所属节点'
|
|
15
|
+
target: 'flow_nodes'
|
|
21
16
|
}, {
|
|
22
|
-
interface: 'linkTo',
|
|
23
17
|
type: 'belongsTo',
|
|
24
18
|
name: 'upstream',
|
|
25
|
-
target: 'jobs'
|
|
26
|
-
|
|
27
|
-
}, // pending / resolved / rejected
|
|
28
|
-
{
|
|
29
|
-
interface: 'status',
|
|
19
|
+
target: 'jobs'
|
|
20
|
+
}, {
|
|
30
21
|
type: 'integer',
|
|
31
|
-
name: 'status'
|
|
32
|
-
title: '处理状态'
|
|
22
|
+
name: 'status'
|
|
33
23
|
}, {
|
|
34
|
-
interface: 'json',
|
|
35
24
|
type: 'jsonb',
|
|
36
|
-
name: 'result'
|
|
37
|
-
|
|
38
|
-
} // TODO: possibly need node snapshot in case if node has been changed
|
|
39
|
-
// {
|
|
40
|
-
// interface: 'json',
|
|
41
|
-
// type: 'jsonb',
|
|
42
|
-
// name: 'nodeSnapshot',
|
|
43
|
-
// title: 'node snapshot'
|
|
44
|
-
// }
|
|
45
|
-
]
|
|
25
|
+
name: 'result'
|
|
26
|
+
}]
|
|
46
27
|
};
|
|
47
28
|
exports.default = _default;
|
|
@@ -3,70 +3,70 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
|
|
8
|
+
function _default() {
|
|
9
|
+
return {
|
|
10
|
+
name: 'workflows',
|
|
11
|
+
fields: [{
|
|
12
|
+
name: 'key',
|
|
13
|
+
type: 'uid'
|
|
14
|
+
}, {
|
|
15
|
+
type: 'string',
|
|
16
|
+
name: 'title',
|
|
17
|
+
required: true
|
|
18
|
+
}, {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
name: 'enabled',
|
|
21
|
+
defaultValue: false
|
|
22
|
+
}, {
|
|
23
|
+
type: 'text',
|
|
24
|
+
name: 'description'
|
|
25
|
+
}, {
|
|
26
|
+
type: 'string',
|
|
27
|
+
name: 'type',
|
|
28
|
+
required: true
|
|
29
|
+
}, {
|
|
30
|
+
type: 'jsonb',
|
|
31
|
+
name: 'config',
|
|
32
|
+
required: true,
|
|
33
|
+
defaultValue: {}
|
|
34
|
+
}, {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
name: 'useTransaction',
|
|
37
|
+
defaultValue: true
|
|
38
|
+
}, {
|
|
39
|
+
type: 'hasMany',
|
|
40
|
+
name: 'nodes',
|
|
41
|
+
target: 'flow_nodes'
|
|
42
|
+
}, {
|
|
43
|
+
type: 'hasMany',
|
|
44
|
+
name: 'executions'
|
|
45
|
+
}, {
|
|
46
|
+
type: 'integer',
|
|
47
|
+
name: 'executed',
|
|
48
|
+
defaultValue: 0
|
|
49
|
+
}, {
|
|
50
|
+
type: 'integer',
|
|
51
|
+
name: 'allExecuted',
|
|
52
|
+
defaultValue: 0
|
|
53
|
+
}, {
|
|
54
|
+
type: 'boolean',
|
|
55
|
+
name: 'current',
|
|
56
|
+
defaultValue: null
|
|
57
|
+
}, {
|
|
58
|
+
type: 'hasMany',
|
|
59
|
+
name: 'revisions',
|
|
60
|
+
target: 'workflows',
|
|
61
|
+
foreignKey: 'key',
|
|
62
|
+
sourceKey: 'key',
|
|
63
|
+
// NOTE: no constraints needed here because tricky self-referencing
|
|
64
|
+
constraints: false
|
|
65
|
+
}],
|
|
66
|
+
// NOTE: use unique index for avoiding deadlock in mysql when setCurrent
|
|
67
|
+
indexes: [{
|
|
68
|
+
unique: true,
|
|
69
|
+
fields: ['key', 'current']
|
|
70
|
+
}]
|
|
71
|
+
};
|
|
72
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export * from './constants';
|
|
2
1
|
export * from './calculators';
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './constants';
|
|
4
3
|
export * from './instructions';
|
|
5
|
-
export
|
|
4
|
+
export * from './triggers';
|
|
5
|
+
export * from './Processor';
|
|
6
|
+
export { default } from './Plugin';
|
package/lib/index.js
CHANGED
|
@@ -7,10 +7,24 @@ var _exportNames = {};
|
|
|
7
7
|
Object.defineProperty(exports, "default", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function get() {
|
|
10
|
-
return
|
|
10
|
+
return _Plugin.default;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
+
var _calculators = require("./calculators");
|
|
15
|
+
|
|
16
|
+
Object.keys(_calculators).forEach(function (key) {
|
|
17
|
+
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
+
if (key in exports && exports[key] === _calculators[key]) return;
|
|
20
|
+
Object.defineProperty(exports, key, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _calculators[key];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
14
28
|
var _constants = require("./constants");
|
|
15
29
|
|
|
16
30
|
Object.keys(_constants).forEach(function (key) {
|
|
@@ -25,16 +39,16 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
25
39
|
});
|
|
26
40
|
});
|
|
27
41
|
|
|
28
|
-
var
|
|
42
|
+
var _instructions = require("./instructions");
|
|
29
43
|
|
|
30
|
-
Object.keys(
|
|
44
|
+
Object.keys(_instructions).forEach(function (key) {
|
|
31
45
|
if (key === "default" || key === "__esModule") return;
|
|
32
46
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
33
|
-
if (key in exports && exports[key] ===
|
|
47
|
+
if (key in exports && exports[key] === _instructions[key]) return;
|
|
34
48
|
Object.defineProperty(exports, key, {
|
|
35
49
|
enumerable: true,
|
|
36
50
|
get: function get() {
|
|
37
|
-
return
|
|
51
|
+
return _instructions[key];
|
|
38
52
|
}
|
|
39
53
|
});
|
|
40
54
|
});
|
|
@@ -53,20 +67,20 @@ Object.keys(_triggers).forEach(function (key) {
|
|
|
53
67
|
});
|
|
54
68
|
});
|
|
55
69
|
|
|
56
|
-
var
|
|
70
|
+
var _Processor = require("./Processor");
|
|
57
71
|
|
|
58
|
-
Object.keys(
|
|
72
|
+
Object.keys(_Processor).forEach(function (key) {
|
|
59
73
|
if (key === "default" || key === "__esModule") return;
|
|
60
74
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
61
|
-
if (key in exports && exports[key] ===
|
|
75
|
+
if (key in exports && exports[key] === _Processor[key]) return;
|
|
62
76
|
Object.defineProperty(exports, key, {
|
|
63
77
|
enumerable: true,
|
|
64
78
|
get: function get() {
|
|
65
|
-
return
|
|
79
|
+
return _Processor[key];
|
|
66
80
|
}
|
|
67
81
|
});
|
|
68
82
|
});
|
|
69
83
|
|
|
70
|
-
var
|
|
84
|
+
var _Plugin = _interopRequireDefault(require("./Plugin"));
|
|
71
85
|
|
|
72
86
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -40,17 +40,15 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
40
40
|
// ]
|
|
41
41
|
// }
|
|
42
42
|
var _default = {
|
|
43
|
-
run(prevJob,
|
|
44
|
-
var _this = this;
|
|
45
|
-
|
|
43
|
+
run(node, prevJob, processor) {
|
|
46
44
|
return _asyncToGenerator(function* () {
|
|
47
|
-
const _ref =
|
|
45
|
+
const _ref = node.config || {},
|
|
48
46
|
calculation = _ref.calculation;
|
|
49
47
|
|
|
50
48
|
const result = calculation ? (0, _calculators.calculate)({
|
|
51
49
|
type: '$calculation',
|
|
52
|
-
options:
|
|
53
|
-
}, prevJob,
|
|
50
|
+
options: processor.getParsedValue(calculation)
|
|
51
|
+
}, prevJob, processor) : null;
|
|
54
52
|
return {
|
|
55
53
|
result,
|
|
56
54
|
status: _constants.JOB_STATUS.RESOLVED
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
run(
|
|
3
|
-
resume(
|
|
2
|
+
run(node: any, prevJob: any, processor: any): Promise<any>;
|
|
3
|
+
resume(node: any, branchJob: any, processor: any): Promise<any>;
|
|
4
4
|
};
|
|
5
5
|
export default _default;
|
|
@@ -44,7 +44,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
44
44
|
// ]
|
|
45
45
|
// }
|
|
46
46
|
// }
|
|
47
|
-
function logicCalculate(calculation, input,
|
|
47
|
+
function logicCalculate(calculation, input, processor) {
|
|
48
48
|
if (!calculation) {
|
|
49
49
|
return true;
|
|
50
50
|
}
|
|
@@ -55,9 +55,9 @@ function logicCalculate(calculation, input, execution) {
|
|
|
55
55
|
|
|
56
56
|
if (group) {
|
|
57
57
|
const method = group.type === 'and' ? 'every' : 'some';
|
|
58
|
-
result = group.calculations[method](item => logicCalculate(item, input,
|
|
58
|
+
result = group.calculations[method](item => logicCalculate(item, input, processor));
|
|
59
59
|
} else {
|
|
60
|
-
const args = calculation.operands.map(operand => (0, _calculators.calculate)(operand, input,
|
|
60
|
+
const args = calculation.operands.map(operand => (0, _calculators.calculate)(operand, input, processor));
|
|
61
61
|
|
|
62
62
|
const fn = _calculators.default.get(calculation.calculator);
|
|
63
63
|
|
|
@@ -72,17 +72,15 @@ function logicCalculate(calculation, input, execution) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
var _default = {
|
|
75
|
-
run(prevJob,
|
|
76
|
-
var _this = this;
|
|
77
|
-
|
|
75
|
+
run(node, prevJob, processor) {
|
|
78
76
|
return _asyncToGenerator(function* () {
|
|
79
|
-
// TODO(optimize): loading of jobs could be reduced and turned into incrementally in
|
|
80
|
-
// const jobs = await
|
|
81
|
-
const _ref =
|
|
77
|
+
// TODO(optimize): loading of jobs could be reduced and turned into incrementally in processor
|
|
78
|
+
// const jobs = await processor.getJobs();
|
|
79
|
+
const _ref = node.config || {},
|
|
82
80
|
calculation = _ref.calculation,
|
|
83
81
|
rejectOnFalse = _ref.rejectOnFalse;
|
|
84
82
|
|
|
85
|
-
const result = logicCalculate(calculation, prevJob,
|
|
83
|
+
const result = logicCalculate(calculation, prevJob, processor);
|
|
86
84
|
|
|
87
85
|
if (!result && rejectOnFalse) {
|
|
88
86
|
return {
|
|
@@ -95,31 +93,29 @@ var _default = {
|
|
|
95
93
|
status: _constants.JOB_STATUS.RESOLVED,
|
|
96
94
|
result,
|
|
97
95
|
// TODO(optimize): try unify the building of job
|
|
98
|
-
nodeId:
|
|
96
|
+
nodeId: node.id,
|
|
99
97
|
upstreamId: prevJob && prevJob.id || null
|
|
100
98
|
};
|
|
101
|
-
const branchNode =
|
|
99
|
+
const branchNode = processor.nodes.find(item => item.upstream === node && Boolean(item.branchIndex) === result);
|
|
102
100
|
|
|
103
101
|
if (!branchNode) {
|
|
104
102
|
return job;
|
|
105
103
|
}
|
|
106
104
|
|
|
107
|
-
const savedJob = yield
|
|
108
|
-
return
|
|
105
|
+
const savedJob = yield processor.saveJob(job);
|
|
106
|
+
return processor.run(branchNode, savedJob);
|
|
109
107
|
})();
|
|
110
108
|
},
|
|
111
109
|
|
|
112
|
-
resume(branchJob,
|
|
113
|
-
var _this2 = this;
|
|
114
|
-
|
|
110
|
+
resume(node, branchJob, processor) {
|
|
115
111
|
return _asyncToGenerator(function* () {
|
|
116
112
|
if (branchJob.status === _constants.JOB_STATUS.RESOLVED) {
|
|
117
|
-
// return to continue
|
|
113
|
+
// return to continue node.downstream
|
|
118
114
|
return branchJob;
|
|
119
115
|
} // pass control to upper scope by ending current scope
|
|
120
116
|
|
|
121
117
|
|
|
122
|
-
return
|
|
118
|
+
return processor.end(node, branchJob);
|
|
123
119
|
})();
|
|
124
120
|
}
|
|
125
121
|
|
|
@@ -18,20 +18,16 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
18
18
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
19
|
|
|
20
20
|
var _default = {
|
|
21
|
-
run(input,
|
|
22
|
-
var _this = this;
|
|
23
|
-
|
|
21
|
+
run(node, input, processor) {
|
|
24
22
|
return _asyncToGenerator(function* () {
|
|
25
|
-
const
|
|
26
|
-
collection =
|
|
27
|
-
|
|
28
|
-
params =
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const options = execution.getParsedValue(params);
|
|
23
|
+
const _node$config = node.config,
|
|
24
|
+
collection = _node$config.collection,
|
|
25
|
+
_node$config$params = _node$config.params,
|
|
26
|
+
params = _node$config$params === void 0 ? {} : _node$config$params;
|
|
27
|
+
const repo = node.constructor.database.getRepository(collection);
|
|
28
|
+
const options = processor.getParsedValue(params);
|
|
33
29
|
const result = yield repo.create(_objectSpread(_objectSpread({}, options), {}, {
|
|
34
|
-
transaction:
|
|
30
|
+
transaction: processor.transaction
|
|
35
31
|
}));
|
|
36
32
|
return {
|
|
37
33
|
// NOTE: get() for non-proxied instance (#380)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Plugin from '..';
|
|
3
|
+
import Processor from '../Processor';
|
|
4
|
+
export default class {
|
|
5
|
+
protected plugin: Plugin;
|
|
6
|
+
timers: Map<number, NodeJS.Timeout>;
|
|
7
|
+
constructor(plugin: Plugin);
|
|
8
|
+
load(): Promise<void>;
|
|
9
|
+
unload(): void;
|
|
10
|
+
schedule(job: any, duration: number): void;
|
|
11
|
+
trigger(job: any): Promise<void>;
|
|
12
|
+
run: (node: any, prevJob: any, processor: Processor) => Promise<any>;
|
|
13
|
+
resume: (node: any, prevJob: any, processor: Processor) => Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
|
|
10
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
11
|
+
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
+
|
|
16
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
|
+
|
|
18
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
|
+
|
|
20
|
+
class _default {
|
|
21
|
+
constructor(plugin) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
|
|
24
|
+
this.plugin = void 0;
|
|
25
|
+
this.timers = new Map();
|
|
26
|
+
|
|
27
|
+
this.run = /*#__PURE__*/function () {
|
|
28
|
+
var _ref = _asyncToGenerator(function* (node, prevJob, processor) {
|
|
29
|
+
var _prevJob$id;
|
|
30
|
+
|
|
31
|
+
const job = yield processor.saveJob({
|
|
32
|
+
status: _constants.JOB_STATUS.PENDING,
|
|
33
|
+
result: null,
|
|
34
|
+
nodeId: node.id,
|
|
35
|
+
upstreamId: (_prevJob$id = prevJob === null || prevJob === void 0 ? void 0 : prevJob.id) !== null && _prevJob$id !== void 0 ? _prevJob$id : null
|
|
36
|
+
});
|
|
37
|
+
const duration = node.config.duration; // add to schedule
|
|
38
|
+
|
|
39
|
+
_this.schedule(job, duration);
|
|
40
|
+
|
|
41
|
+
return processor.end(node, job);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return function (_x, _x2, _x3) {
|
|
45
|
+
return _ref.apply(this, arguments);
|
|
46
|
+
};
|
|
47
|
+
}();
|
|
48
|
+
|
|
49
|
+
this.resume = /*#__PURE__*/function () {
|
|
50
|
+
var _ref2 = _asyncToGenerator(function* (node, prevJob, processor) {
|
|
51
|
+
const endStatus = node.config.endStatus;
|
|
52
|
+
prevJob.set('status', endStatus);
|
|
53
|
+
return prevJob;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return function (_x4, _x5, _x6) {
|
|
57
|
+
return _ref2.apply(this, arguments);
|
|
58
|
+
};
|
|
59
|
+
}();
|
|
60
|
+
|
|
61
|
+
this.plugin = plugin;
|
|
62
|
+
plugin.app.on('beforeStart', () => this.load());
|
|
63
|
+
plugin.app.on('beforeStop', () => this.unload());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
load() {
|
|
67
|
+
var _this2 = this;
|
|
68
|
+
|
|
69
|
+
return _asyncToGenerator(function* () {
|
|
70
|
+
const _this2$plugin$db$getC = _this2.plugin.db.getCollection('jobs'),
|
|
71
|
+
model = _this2$plugin$db$getC.model;
|
|
72
|
+
|
|
73
|
+
const jobs = yield model.findAll({
|
|
74
|
+
where: {
|
|
75
|
+
status: _constants.JOB_STATUS.PENDING
|
|
76
|
+
},
|
|
77
|
+
include: [{
|
|
78
|
+
association: 'execution'
|
|
79
|
+
}, {
|
|
80
|
+
association: 'node',
|
|
81
|
+
where: {
|
|
82
|
+
type: 'delay'
|
|
83
|
+
},
|
|
84
|
+
required: true
|
|
85
|
+
}]
|
|
86
|
+
});
|
|
87
|
+
jobs.forEach(job => {
|
|
88
|
+
_this2.schedule(job, job.node.config.duration);
|
|
89
|
+
});
|
|
90
|
+
})();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
unload() {
|
|
94
|
+
var _iterator = _createForOfIteratorHelper(this.timers.values()),
|
|
95
|
+
_step;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
99
|
+
const timer = _step.value;
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
}
|
|
102
|
+
} catch (err) {
|
|
103
|
+
_iterator.e(err);
|
|
104
|
+
} finally {
|
|
105
|
+
_iterator.f();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.timers = new Map();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
schedule(job, duration) {
|
|
112
|
+
const now = new Date();
|
|
113
|
+
const createdAt = Date.parse(job.createdAt);
|
|
114
|
+
const delay = createdAt + duration - now.getTime();
|
|
115
|
+
const trigger = this.trigger.bind(this, job);
|
|
116
|
+
this.timers.set(job.id, setTimeout(trigger, Math.max(0, delay)));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
trigger(job) {
|
|
120
|
+
var _this3 = this;
|
|
121
|
+
|
|
122
|
+
return _asyncToGenerator(function* () {
|
|
123
|
+
const _job$execution = job.execution,
|
|
124
|
+
execution = _job$execution === void 0 ? yield job.getExecution() : _job$execution;
|
|
125
|
+
|
|
126
|
+
const processor = _this3.plugin.createProcessor(execution);
|
|
127
|
+
|
|
128
|
+
yield processor.resume(job);
|
|
129
|
+
|
|
130
|
+
if (_this3.timers.get(job.id)) {
|
|
131
|
+
_this3.timers.delete(job.id);
|
|
132
|
+
}
|
|
133
|
+
})();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.default = _default;
|
|
@@ -18,20 +18,16 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
18
18
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
19
19
|
|
|
20
20
|
var _default = {
|
|
21
|
-
run(input,
|
|
22
|
-
var _this = this;
|
|
23
|
-
|
|
21
|
+
run(node, input, processor) {
|
|
24
22
|
return _asyncToGenerator(function* () {
|
|
25
|
-
const
|
|
26
|
-
collection =
|
|
27
|
-
|
|
28
|
-
params =
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const options = execution.getParsedValue(params);
|
|
23
|
+
const _node$config = node.config,
|
|
24
|
+
collection = _node$config.collection,
|
|
25
|
+
_node$config$params = _node$config.params,
|
|
26
|
+
params = _node$config$params === void 0 ? {} : _node$config$params;
|
|
27
|
+
const repo = node.constructor.database.getRepository(collection);
|
|
28
|
+
const options = processor.getParsedValue(params);
|
|
33
29
|
const result = yield repo.destroy(_objectSpread(_objectSpread({}, options), {}, {
|
|
34
|
-
transaction:
|
|
30
|
+
transaction: processor.transaction
|
|
35
31
|
}));
|
|
36
32
|
return {
|
|
37
33
|
result,
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { Registry } from '@nocobase/utils';
|
|
2
|
-
import ExecutionModel from '../models/Execution';
|
|
3
1
|
import FlowNodeModel from '../models/FlowNode';
|
|
4
|
-
|
|
2
|
+
import Plugin from '..';
|
|
3
|
+
import Processor from '../Processor';
|
|
4
|
+
export declare type Job = {
|
|
5
5
|
status: number;
|
|
6
6
|
result?: unknown;
|
|
7
7
|
[key: string]: unknown;
|
|
8
|
-
}
|
|
8
|
+
} | null;
|
|
9
9
|
export declare type InstructionResult = Job | Promise<Job>;
|
|
10
10
|
export interface Instruction {
|
|
11
|
-
run(
|
|
12
|
-
resume?(
|
|
11
|
+
run(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
|
|
12
|
+
resume?(node: FlowNodeModel, input: any, processor: Processor): InstructionResult;
|
|
13
13
|
}
|
|
14
|
-
export
|
|
15
|
-
|
|
14
|
+
export default function <T extends Instruction>(plugin: any, more?: {
|
|
15
|
+
[key: string]: T | {
|
|
16
|
+
new (p: Plugin): T;
|
|
17
|
+
};
|
|
18
|
+
}): void;
|