@nocobase/plugin-workflow 0.9.1-alpha.1 → 0.9.2-alpha.1
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/client/AddButton.js +50 -86
- package/lib/client/Branch.js +0 -13
- package/lib/client/ExecutionCanvas.js +16 -63
- package/lib/client/ExecutionLink.js +3 -21
- package/lib/client/ExecutionPage.js +1 -19
- package/lib/client/ExecutionResourceProvider.js +6 -23
- package/lib/client/FlowContext.js +0 -8
- package/lib/client/WorkflowCanvas.js +57 -129
- package/lib/client/WorkflowLink.js +3 -21
- package/lib/client/WorkflowPage.js +1 -19
- package/lib/client/WorkflowProvider.js +24 -47
- package/lib/client/WorkflowShortcut.js +0 -16
- package/lib/client/components/CollectionBlockInitializer.js +12 -22
- package/lib/client/components/CollectionFieldInitializers.js +5 -24
- package/lib/client/components/CollectionFieldset.js +33 -85
- package/lib/client/components/Duration.js +0 -14
- package/lib/client/components/DynamicExpression.d.ts +4 -0
- package/lib/client/components/DynamicExpression.js +102 -0
- package/lib/client/components/FieldsSelect.d.ts +2 -0
- package/lib/client/components/FieldsSelect.js +66 -0
- package/lib/client/components/FilterDynamicComponent.js +1 -10
- package/lib/client/components/NullRender.js +0 -1
- package/lib/client/components/OpenDrawer.js +10 -35
- package/lib/client/components/RadioWithTooltip.js +5 -27
- package/lib/client/components/renderEngineReference.d.ts +1 -0
- package/lib/client/components/renderEngineReference.js +55 -0
- package/lib/client/constants.js +0 -9
- package/lib/client/index.js +0 -6
- package/lib/client/interfaces/expression.d.ts +3 -0
- package/lib/client/interfaces/expression.js +37 -0
- package/lib/client/locale/index.js +5 -15
- package/lib/client/locale/pt-BR.d.ts +130 -0
- package/lib/client/locale/pt-BR.js +136 -0
- package/lib/client/locale/zh-CN.d.ts +16 -1
- package/lib/client/locale/zh-CN.js +17 -2
- package/lib/client/nodes/calculation.d.ts +56 -7
- package/lib/client/nodes/calculation.js +141 -74
- package/lib/client/nodes/condition.d.ts +5 -9
- package/lib/client/nodes/condition.js +30 -93
- package/lib/client/nodes/create.d.ts +36 -12
- package/lib/client/nodes/create.js +14 -28
- package/lib/client/nodes/delay.d.ts +3 -7
- package/lib/client/nodes/delay.js +5 -14
- package/lib/client/nodes/destroy.d.ts +3 -11
- package/lib/client/nodes/destroy.js +14 -12
- package/lib/client/nodes/index.d.ts +2 -2
- package/lib/client/nodes/index.js +181 -222
- package/lib/client/nodes/manual/AssigneesSelect.js +8 -18
- package/lib/client/nodes/manual/ModeConfig.js +0 -27
- package/lib/client/nodes/manual/SchemaConfig.js +87 -449
- package/lib/client/nodes/manual/WorkflowTodo.js +99 -163
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +4 -20
- package/lib/client/nodes/manual/forms/customForm.d.ts +40 -0
- package/lib/client/nodes/manual/forms/customForm.js +411 -0
- package/lib/client/nodes/manual/index.d.ts +15 -6
- package/lib/client/nodes/manual/index.js +58 -54
- package/lib/client/nodes/parallel.d.ts +1 -2
- package/lib/client/nodes/parallel.js +16 -45
- package/lib/client/nodes/query.d.ts +30 -12
- package/lib/client/nodes/query.js +17 -25
- package/lib/client/nodes/request.d.ts +9 -17
- package/lib/client/nodes/request.js +13 -37
- package/lib/client/nodes/update.d.ts +27 -28
- package/lib/client/nodes/update.js +17 -18
- package/lib/client/schemas/collection.d.ts +20 -7
- package/lib/client/schemas/collection.js +27 -28
- package/lib/client/schemas/executions.js +3 -18
- package/lib/client/schemas/workflows.js +10 -33
- package/lib/client/style.js +75 -26
- package/lib/client/triggers/collection.d.ts +47 -18
- package/lib/client/triggers/collection.js +65 -123
- package/lib/client/triggers/index.d.ts +3 -6
- package/lib/client/triggers/index.js +146 -146
- package/lib/client/triggers/schedule/DateFieldsSelect.js +7 -32
- package/lib/client/triggers/schedule/EndsByField.js +1 -18
- package/lib/client/triggers/schedule/OnField.js +10 -38
- package/lib/client/triggers/schedule/RepeatField.js +4 -32
- package/lib/client/triggers/schedule/ScheduleConfig.js +25 -68
- package/lib/client/triggers/schedule/index.d.ts +21 -1
- package/lib/client/triggers/schedule/index.js +22 -24
- package/lib/client/triggers/schedule/locale/Cron.zh-CN.js +8 -4
- package/lib/client/utils.d.ts +1 -0
- package/lib/client/utils.js +31 -10
- package/lib/client/variable.d.ts +7 -6
- package/lib/client/variable.js +132 -71
- package/lib/index.js +0 -2
- package/lib/server/Plugin.d.ts +7 -7
- package/lib/server/Plugin.js +76 -111
- package/lib/server/Processor.d.ts +2 -0
- package/lib/server/Processor.js +62 -125
- package/lib/server/actions/index.js +3 -10
- package/lib/server/actions/nodes.js +34 -87
- package/lib/server/actions/workflows.js +46 -96
- package/lib/server/collections/executions.js +1 -1
- package/lib/server/collections/flow_nodes.js +7 -4
- package/lib/server/collections/jobs.js +1 -1
- package/lib/server/collections/workflows.js +3 -4
- package/lib/server/fields/expression-field.d.ts +8 -0
- package/lib/server/fields/expression-field.js +26 -0
- package/lib/server/fields/index.d.ts +1 -0
- package/lib/server/fields/index.js +12 -0
- package/lib/server/functions/index.js +3 -14
- package/lib/server/index.js +0 -6
- package/lib/server/instructions/calculation.js +22 -17
- package/lib/server/instructions/condition.js +8 -52
- package/lib/server/instructions/create.js +31 -15
- package/lib/server/instructions/delay.js +4 -32
- package/lib/server/instructions/destroy.js +6 -12
- package/lib/server/instructions/index.js +6 -23
- package/lib/server/instructions/manual/actions.js +22 -31
- package/lib/server/instructions/manual/collecions/users_jobs.js +1 -1
- package/lib/server/instructions/manual/index.d.ts +13 -12
- package/lib/server/instructions/manual/index.js +9 -47
- package/lib/server/instructions/parallel.js +9 -36
- package/lib/server/instructions/query.js +17 -15
- package/lib/server/instructions/request.js +7 -30
- package/lib/server/instructions/update.js +8 -14
- package/lib/server/migrations/20221129153547-calculation-variables.js +3 -27
- package/lib/server/migrations/20230221032941-change-request-body-type.js +3 -26
- package/lib/server/migrations/20230221071831-calculation-expression.js +1 -33
- package/lib/server/migrations/20230221121203-condition-calculation.js +5 -28
- package/lib/server/migrations/20230221162902-jsonb-to-json.js +3 -18
- package/lib/server/migrations/20230411034722-manual-multi-form.d.ts +4 -0
- package/lib/server/migrations/20230411034722-manual-multi-form.js +303 -0
- package/lib/server/models/Execution.js +0 -5
- package/lib/server/models/FlowNode.js +0 -5
- package/lib/server/models/Job.js +0 -5
- package/lib/server/models/Workflow.js +0 -5
- package/lib/server/triggers/collection.js +39 -61
- package/lib/server/triggers/index.js +3 -22
- package/lib/server/triggers/schedule.js +72 -194
- package/package.json +14 -11
package/lib/server/Plugin.js
CHANGED
|
@@ -4,87 +4,79 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _path() {
|
|
9
8
|
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
9
|
_path = function _path() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
14
|
+
function _winston() {
|
|
15
|
+
const data = _interopRequireDefault(require("winston"));
|
|
16
|
+
_winston = function _winston() {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _lruCache() {
|
|
22
|
+
const data = _interopRequireDefault(require("lru-cache"));
|
|
23
|
+
_lruCache = function _lruCache() {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
18
28
|
function _database() {
|
|
19
29
|
const data = require("@nocobase/database");
|
|
20
|
-
|
|
21
30
|
_database = function _database() {
|
|
22
31
|
return data;
|
|
23
32
|
};
|
|
24
|
-
|
|
25
33
|
return data;
|
|
26
34
|
}
|
|
27
|
-
|
|
28
35
|
function _server() {
|
|
29
36
|
const data = require("@nocobase/server");
|
|
30
|
-
|
|
31
37
|
_server = function _server() {
|
|
32
38
|
return data;
|
|
33
39
|
};
|
|
34
|
-
|
|
35
40
|
return data;
|
|
36
41
|
}
|
|
37
|
-
|
|
38
42
|
function _utils() {
|
|
39
43
|
const data = require("@nocobase/utils");
|
|
40
|
-
|
|
41
44
|
_utils = function _utils() {
|
|
42
45
|
return data;
|
|
43
46
|
};
|
|
44
|
-
|
|
45
47
|
return data;
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
var _fields = _interopRequireDefault(require("./fields"));
|
|
48
50
|
var _actions = _interopRequireDefault(require("./actions"));
|
|
49
|
-
|
|
50
51
|
var _constants = require("./constants");
|
|
51
|
-
|
|
52
52
|
var _instructions = _interopRequireDefault(require("./instructions"));
|
|
53
|
-
|
|
54
53
|
var _Processor = _interopRequireDefault(require("./Processor"));
|
|
55
|
-
|
|
56
54
|
var _triggers = _interopRequireDefault(require("./triggers"));
|
|
57
|
-
|
|
58
55
|
var _functions = _interopRequireDefault(require("./functions"));
|
|
59
|
-
|
|
56
|
+
function _logger() {
|
|
57
|
+
const data = require("@nocobase/logger");
|
|
58
|
+
_logger = function _logger() {
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
60
63
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
61
|
-
|
|
62
64
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
63
|
-
|
|
64
65
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
65
|
-
|
|
66
|
-
function
|
|
67
|
-
|
|
66
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
67
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
68
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
68
69
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
69
|
-
|
|
70
70
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
71
|
-
|
|
72
71
|
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); }
|
|
73
|
-
|
|
74
72
|
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; }
|
|
75
|
-
|
|
76
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
77
|
-
|
|
73
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
78
74
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
79
|
-
|
|
80
75
|
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); } }
|
|
81
|
-
|
|
82
76
|
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); }); }; }
|
|
83
|
-
|
|
84
77
|
class WorkflowPlugin extends _server().Plugin {
|
|
85
78
|
constructor(...args) {
|
|
86
79
|
var _this;
|
|
87
|
-
|
|
88
80
|
super(...args);
|
|
89
81
|
_this = this;
|
|
90
82
|
this.instructions = new (_utils().Registry)();
|
|
@@ -93,11 +85,10 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
93
85
|
this.executing = null;
|
|
94
86
|
this.pending = [];
|
|
95
87
|
this.events = [];
|
|
96
|
-
|
|
88
|
+
this.loggerCache = void 0;
|
|
97
89
|
this.onBeforeSave = /*#__PURE__*/function () {
|
|
98
90
|
var _ref = _asyncToGenerator(function* (instance, options) {
|
|
99
91
|
const Model = instance.constructor;
|
|
100
|
-
|
|
101
92
|
if (instance.enabled) {
|
|
102
93
|
instance.set('current', true);
|
|
103
94
|
} else if (!instance.current) {
|
|
@@ -107,16 +98,13 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
107
98
|
},
|
|
108
99
|
transaction: options.transaction
|
|
109
100
|
});
|
|
110
|
-
|
|
111
101
|
if (!count) {
|
|
112
102
|
instance.set('current', true);
|
|
113
103
|
}
|
|
114
104
|
}
|
|
115
|
-
|
|
116
105
|
if (!instance.changed('enabled') || !instance.enabled) {
|
|
117
106
|
return;
|
|
118
107
|
}
|
|
119
|
-
|
|
120
108
|
const previous = yield Model.findOne({
|
|
121
109
|
where: {
|
|
122
110
|
key: instance.key,
|
|
@@ -127,7 +115,6 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
127
115
|
},
|
|
128
116
|
transaction: options.transaction
|
|
129
117
|
});
|
|
130
|
-
|
|
131
118
|
if (previous) {
|
|
132
119
|
// NOTE: set to `null` but not `false` will not violate the unique index
|
|
133
120
|
yield previous.update({
|
|
@@ -137,32 +124,24 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
137
124
|
transaction: options.transaction,
|
|
138
125
|
hooks: false
|
|
139
126
|
});
|
|
140
|
-
|
|
141
127
|
_this.toggle(previous, false);
|
|
142
128
|
}
|
|
143
129
|
});
|
|
144
|
-
|
|
145
130
|
return function (_x, _x2) {
|
|
146
131
|
return _ref.apply(this, arguments);
|
|
147
132
|
};
|
|
148
133
|
}();
|
|
149
|
-
|
|
150
134
|
this.prepare = /*#__PURE__*/_asyncToGenerator(function* () {
|
|
151
135
|
var _options$context;
|
|
152
|
-
|
|
153
136
|
const event = _this.events.shift();
|
|
154
|
-
|
|
155
137
|
if (!event) {
|
|
156
138
|
return;
|
|
157
139
|
}
|
|
158
|
-
|
|
159
140
|
const _event = _slicedToArray(event, 3),
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
141
|
+
workflow = _event[0],
|
|
142
|
+
context = _event[1],
|
|
143
|
+
options = _event[2];
|
|
164
144
|
let valid = true;
|
|
165
|
-
|
|
166
145
|
if ((_options$context = options.context) === null || _options$context === void 0 ? void 0 : _options$context.executionId) {
|
|
167
146
|
// NOTE: no transaction here for read-uncommitted execution
|
|
168
147
|
const existed = yield workflow.countExecutions({
|
|
@@ -170,14 +149,11 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
170
149
|
id: options.context.executionId
|
|
171
150
|
}
|
|
172
151
|
});
|
|
173
|
-
|
|
174
152
|
if (existed) {
|
|
175
|
-
_this.
|
|
176
|
-
|
|
153
|
+
_this.getLogger(workflow.id).warn(`workflow ${workflow.id} has already been triggered in same execution (${options.context.executionId}), and newly triggering will be skipped.`);
|
|
177
154
|
valid = false;
|
|
178
155
|
}
|
|
179
156
|
}
|
|
180
|
-
|
|
181
157
|
if (valid) {
|
|
182
158
|
const execution = yield _this.db.sequelize.transaction( /*#__PURE__*/function () {
|
|
183
159
|
var _ref3 = _asyncToGenerator(function* (transaction) {
|
|
@@ -191,8 +167,8 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
191
167
|
});
|
|
192
168
|
const executed = yield workflow.countExecutions({
|
|
193
169
|
transaction
|
|
194
|
-
});
|
|
195
|
-
|
|
170
|
+
});
|
|
171
|
+
// NOTE: not to trigger afterUpdate hook here
|
|
196
172
|
yield workflow.update({
|
|
197
173
|
executed
|
|
198
174
|
}, {
|
|
@@ -217,20 +193,18 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
217
193
|
execution.workflow = workflow;
|
|
218
194
|
return execution;
|
|
219
195
|
});
|
|
220
|
-
|
|
221
196
|
return function (_x3) {
|
|
222
197
|
return _ref3.apply(this, arguments);
|
|
223
198
|
};
|
|
224
199
|
}());
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
200
|
+
_this.getLogger(workflow.id).debug(`execution of workflow ${workflow.id} created as ${execution.id}`, {
|
|
201
|
+
data: execution.context
|
|
202
|
+
});
|
|
203
|
+
// NOTE: cache first execution for most cases
|
|
229
204
|
if (!_this.executing && !_this.pending.length) {
|
|
230
205
|
_this.pending.push([execution]);
|
|
231
206
|
}
|
|
232
207
|
}
|
|
233
|
-
|
|
234
208
|
if (_this.events.length) {
|
|
235
209
|
yield _this.prepare();
|
|
236
210
|
} else {
|
|
@@ -238,29 +212,47 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
238
212
|
}
|
|
239
213
|
});
|
|
240
214
|
}
|
|
241
|
-
|
|
215
|
+
getLogger(workflowId) {
|
|
216
|
+
const now = new Date();
|
|
217
|
+
const date = `${now.getFullYear()}-${`0${now.getMonth() + 1}`.slice(-2)}-${`0${now.getDate()}`.slice(-2)}`;
|
|
218
|
+
const key = `${date}-${workflowId}}`;
|
|
219
|
+
if (this.loggerCache.has(key)) {
|
|
220
|
+
return this.loggerCache.get(key);
|
|
221
|
+
}
|
|
222
|
+
const logger = (0, _logger().createLogger)({
|
|
223
|
+
transports: ['console', new (_winston().default.transports.File)({
|
|
224
|
+
filename: (0, _logger().getLoggerFilePath)('workflows', date, `${workflowId}.log`),
|
|
225
|
+
level: (0, _logger().getLoggerLevel)()
|
|
226
|
+
})]
|
|
227
|
+
});
|
|
228
|
+
this.loggerCache.set(key, logger);
|
|
229
|
+
return logger;
|
|
230
|
+
}
|
|
242
231
|
load() {
|
|
243
232
|
var _this2 = this;
|
|
244
|
-
|
|
245
233
|
return _asyncToGenerator(function* () {
|
|
246
234
|
const db = _this2.db,
|
|
247
|
-
|
|
235
|
+
options = _this2.options;
|
|
236
|
+
(0, _fields.default)(_this2);
|
|
248
237
|
(0, _actions.default)(_this2);
|
|
249
238
|
(0, _triggers.default)(_this2, options.triggers);
|
|
250
239
|
(0, _instructions.default)(_this2, options.instructions);
|
|
251
240
|
(0, _functions.default)(_this2, options.functions);
|
|
252
|
-
|
|
241
|
+
_this2.loggerCache = new (_lruCache().default)({
|
|
242
|
+
max: 20,
|
|
243
|
+
updateAgeOnGet: true,
|
|
244
|
+
dispose(logger) {
|
|
245
|
+
logger.end();
|
|
246
|
+
}
|
|
247
|
+
});
|
|
253
248
|
_this2.app.acl.registerSnippet({
|
|
254
249
|
name: `pm.${_this2.name}.workflows`,
|
|
255
250
|
actions: ['workflows:*', 'workflows.nodes:*', 'executions:list', 'executions:get', 'flow_nodes:update', 'flow_nodes:destroy']
|
|
256
251
|
});
|
|
257
|
-
|
|
258
252
|
_this2.app.acl.allow('users_jobs', ['list', 'get', 'submit'], 'loggedIn');
|
|
259
|
-
|
|
260
253
|
yield db.import({
|
|
261
254
|
directory: _path().default.resolve(__dirname, 'collections')
|
|
262
255
|
});
|
|
263
|
-
|
|
264
256
|
_this2.db.addMigrations({
|
|
265
257
|
namespace: 'workflow',
|
|
266
258
|
directory: _path().default.resolve(__dirname, 'migrations'),
|
|
@@ -268,14 +260,13 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
268
260
|
plugin: _this2
|
|
269
261
|
}
|
|
270
262
|
});
|
|
271
|
-
|
|
272
263
|
db.on('workflows.beforeSave', _this2.onBeforeSave);
|
|
273
264
|
db.on('workflows.afterSave', model => _this2.toggle(model));
|
|
274
|
-
db.on('workflows.afterDestroy', model => _this2.toggle(model, false));
|
|
265
|
+
db.on('workflows.afterDestroy', model => _this2.toggle(model, false));
|
|
266
|
+
// [Life Cycle]:
|
|
275
267
|
// * load all workflows in db
|
|
276
268
|
// * add all hooks for enabled workflows
|
|
277
269
|
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
|
|
278
|
-
|
|
279
270
|
_this2.app.on('beforeStart', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
280
271
|
const collection = db.getCollection('workflows');
|
|
281
272
|
const workflows = yield collection.repository.find({
|
|
@@ -285,11 +276,10 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
285
276
|
});
|
|
286
277
|
workflows.forEach(workflow => {
|
|
287
278
|
_this2.toggle(workflow);
|
|
288
|
-
});
|
|
289
|
-
|
|
279
|
+
});
|
|
280
|
+
// check for not started executions
|
|
290
281
|
_this2.dispatch();
|
|
291
282
|
}));
|
|
292
|
-
|
|
293
283
|
_this2.app.on('beforeStop', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
294
284
|
const collection = db.getCollection('workflows');
|
|
295
285
|
const workflows = yield collection.repository.find({
|
|
@@ -303,66 +293,53 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
303
293
|
}));
|
|
304
294
|
})();
|
|
305
295
|
}
|
|
306
|
-
|
|
307
296
|
toggle(workflow, enable) {
|
|
308
297
|
const type = workflow.get('type');
|
|
309
298
|
const trigger = this.triggers.get(type);
|
|
310
|
-
|
|
311
299
|
if (typeof enable !== 'undefined' ? enable : workflow.get('enabled')) {
|
|
312
300
|
// NOTE: remove previous listener if config updated
|
|
313
301
|
const prev = workflow.previous();
|
|
314
|
-
|
|
315
302
|
if (prev.config) {
|
|
316
303
|
trigger.off(_objectSpread(_objectSpread({}, workflow.get()), prev));
|
|
317
304
|
}
|
|
318
|
-
|
|
319
305
|
trigger.on(workflow);
|
|
320
306
|
} else {
|
|
321
307
|
trigger.off(workflow);
|
|
322
308
|
}
|
|
323
309
|
}
|
|
324
|
-
|
|
325
310
|
trigger(workflow, context, options = {}) {
|
|
326
311
|
// `null` means not to trigger
|
|
327
312
|
if (context == null) {
|
|
328
313
|
return;
|
|
329
314
|
}
|
|
330
|
-
|
|
331
315
|
this.events.push([workflow, context, options]);
|
|
332
|
-
this.
|
|
333
|
-
|
|
316
|
+
this.getLogger(workflow.id).debug(`new event triggered, now events: ${this.events.length}`, {
|
|
317
|
+
data: workflow.config
|
|
318
|
+
});
|
|
334
319
|
if (this.events.length > 1) {
|
|
335
320
|
return;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
321
|
+
}
|
|
322
|
+
// NOTE: no await for quick return
|
|
339
323
|
setTimeout(this.prepare);
|
|
340
324
|
}
|
|
341
|
-
|
|
342
325
|
resume(job) {
|
|
343
326
|
var _this3 = this;
|
|
344
|
-
|
|
345
327
|
return _asyncToGenerator(function* () {
|
|
346
328
|
if (!job.execution) {
|
|
347
329
|
job.execution = yield job.getExecution();
|
|
348
330
|
}
|
|
349
|
-
|
|
350
331
|
_this3.pending.push([job.execution, job]);
|
|
351
|
-
|
|
352
332
|
_this3.dispatch();
|
|
353
333
|
})();
|
|
354
334
|
}
|
|
355
|
-
|
|
356
335
|
dispatch() {
|
|
357
336
|
var _this4 = this;
|
|
358
|
-
|
|
359
337
|
return _asyncToGenerator(function* () {
|
|
360
338
|
if (_this4.executing) {
|
|
361
339
|
return;
|
|
362
340
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
341
|
+
let next = null;
|
|
342
|
+
// resuming has high priority
|
|
366
343
|
if (_this4.pending.length) {
|
|
367
344
|
next = _this4.pending.shift();
|
|
368
345
|
} else {
|
|
@@ -372,52 +349,40 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
372
349
|
},
|
|
373
350
|
sort: 'createdAt'
|
|
374
351
|
});
|
|
375
|
-
|
|
376
352
|
if (execution) {
|
|
377
353
|
next = [execution];
|
|
378
354
|
}
|
|
379
355
|
}
|
|
380
|
-
|
|
381
356
|
if (next) {
|
|
382
357
|
_this4.process(...next);
|
|
383
358
|
}
|
|
384
359
|
})();
|
|
385
360
|
}
|
|
386
|
-
|
|
387
361
|
process(execution, job) {
|
|
388
362
|
var _this5 = this;
|
|
389
|
-
|
|
390
363
|
return _asyncToGenerator(function* () {
|
|
391
364
|
_this5.executing = execution;
|
|
392
|
-
|
|
393
365
|
if (execution.status === _constants.EXECUTION_STATUS.QUEUEING) {
|
|
394
366
|
yield execution.update({
|
|
395
367
|
status: _constants.EXECUTION_STATUS.STARTED
|
|
396
368
|
});
|
|
397
369
|
}
|
|
398
|
-
|
|
399
370
|
const processor = _this5.createProcessor(execution);
|
|
400
|
-
|
|
401
|
-
_this5.app.logger.info(`[Workflow] execution ${execution.id} ${job ? 'resuming' : 'starting'}...`);
|
|
402
|
-
|
|
371
|
+
_this5.getLogger(execution.workflowId).info(`execution (${execution.id}) ${job ? 'resuming' : 'starting'}...`);
|
|
403
372
|
try {
|
|
404
373
|
yield job ? processor.resume(job) : processor.start();
|
|
374
|
+
_this5.getLogger(execution.workflowId).info(`execution (${execution.id}) finished with status: ${execution.status}`);
|
|
405
375
|
} catch (err) {
|
|
406
|
-
_this5.
|
|
376
|
+
_this5.getLogger(execution.workflowId).error(`execution (${execution.id}) error: ${err.message}`, err);
|
|
407
377
|
}
|
|
408
|
-
|
|
409
378
|
_this5.executing = null;
|
|
410
|
-
|
|
411
379
|
_this5.dispatch();
|
|
412
380
|
})();
|
|
413
381
|
}
|
|
414
|
-
|
|
415
382
|
createProcessor(execution, options = {}) {
|
|
416
383
|
return new _Processor.default(execution, _objectSpread(_objectSpread({}, options), {}, {
|
|
417
384
|
plugin: this
|
|
418
385
|
}));
|
|
419
386
|
}
|
|
420
|
-
|
|
421
387
|
}
|
|
422
|
-
|
|
423
388
|
exports.default = WorkflowPlugin;
|
|
@@ -3,6 +3,7 @@ import Plugin from '.';
|
|
|
3
3
|
import ExecutionModel from './models/Execution';
|
|
4
4
|
import JobModel from './models/Job';
|
|
5
5
|
import FlowNodeModel from './models/FlowNode';
|
|
6
|
+
import { Logger } from '@nocobase/logger';
|
|
6
7
|
export interface ProcessorOptions extends Transactionable {
|
|
7
8
|
plugin: Plugin;
|
|
8
9
|
}
|
|
@@ -12,6 +13,7 @@ export default class Processor {
|
|
|
12
13
|
static StatusMap: {
|
|
13
14
|
[x: number]: number;
|
|
14
15
|
};
|
|
16
|
+
logger: Logger;
|
|
15
17
|
transaction?: Transaction;
|
|
16
18
|
nodes: FlowNodeModel[];
|
|
17
19
|
nodesMap: Map<number, FlowNodeModel>;
|