@nocobase/plugin-workflow 0.8.0-alpha.9 → 0.8.1-alpha.3
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 +21 -13
- package/lib/client/ExecutionCanvas.js +9 -21
- package/lib/client/ExecutionResourceProvider.d.ts +2 -1
- package/lib/client/ExecutionResourceProvider.js +4 -3
- package/lib/client/FlowContext.js +1 -1
- package/lib/client/WorkflowCanvas.js +135 -36
- package/lib/client/WorkflowProvider.d.ts +3 -0
- package/lib/client/WorkflowProvider.js +71 -16
- package/lib/client/WorkflowShortcut.d.ts +0 -1
- package/lib/client/WorkflowShortcut.js +4 -47
- package/lib/client/calculators.d.ts +27 -37
- package/lib/client/calculators.js +168 -150
- package/lib/client/components/CollectionFieldset.js +10 -20
- package/lib/client/components/Duration.js +3 -14
- package/lib/client/components/EjsTextArea.d.ts +2 -0
- package/lib/client/components/EjsTextArea.js +232 -0
- package/lib/client/components/OpenDrawer.d.ts +6 -0
- package/lib/client/components/OpenDrawer.js +93 -0
- package/lib/client/constants.js +11 -9
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +14 -0
- package/lib/client/locale/en-US.d.ts +105 -0
- package/lib/client/locale/en-US.js +111 -0
- package/lib/client/locale/index.d.ts +3 -0
- package/lib/client/locale/index.js +69 -0
- package/lib/client/locale/ja-JP.d.ts +88 -0
- package/lib/client/locale/ja-JP.js +94 -0
- package/lib/client/locale/ru-RU.d.ts +88 -0
- package/lib/client/locale/ru-RU.js +94 -0
- package/lib/client/locale/tr-TR.d.ts +88 -0
- package/lib/client/locale/tr-TR.js +94 -0
- package/lib/client/locale/zh-CN.d.ts +130 -0
- package/lib/client/locale/zh-CN.js +136 -0
- package/lib/client/nodes/calculation.d.ts +0 -1
- package/lib/client/nodes/calculation.js +9 -17
- package/lib/client/nodes/condition.js +16 -22
- package/lib/client/nodes/create.d.ts +3 -1
- package/lib/client/nodes/create.js +11 -11
- package/lib/client/nodes/delay.js +8 -6
- package/lib/client/nodes/index.js +46 -14
- package/lib/client/nodes/parallel.d.ts +0 -1
- package/lib/client/nodes/parallel.js +11 -32
- package/lib/client/nodes/query.js +9 -17
- package/lib/client/nodes/request.d.ts +138 -0
- package/lib/client/nodes/request.js +167 -0
- package/lib/client/nodes/update.js +4 -2
- package/lib/client/schemas/collection.js +3 -1
- package/lib/client/schemas/executions.d.ts +211 -207
- package/lib/client/schemas/executions.js +102 -96
- package/lib/client/schemas/workflows.js +112 -22
- package/lib/client/style.js +7 -7
- package/lib/client/triggers/collection.d.ts +2 -1
- package/lib/client/triggers/collection.js +49 -34
- package/lib/client/triggers/index.d.ts +3 -3
- package/lib/client/triggers/index.js +46 -46
- package/lib/client/triggers/schedule/EndsByField.js +13 -39
- package/lib/client/triggers/schedule/OnField.js +10 -5
- package/lib/client/triggers/schedule/RepeatField.js +6 -14
- package/lib/client/triggers/schedule/ScheduleConfig.js +25 -20
- package/lib/client/triggers/schedule/constants.d.ts +4 -0
- package/lib/client/triggers/schedule/constants.js +11 -0
- package/lib/client/triggers/schedule/index.d.ts +2 -3
- package/lib/client/triggers/schedule/index.js +55 -40
- package/lib/server/Plugin.d.ts +15 -5
- package/lib/server/Plugin.js +176 -61
- package/lib/server/Processor.d.ts +1 -2
- package/lib/server/Processor.js +3 -19
- package/lib/server/actions/jobs.js +2 -3
- package/lib/server/actions/workflows.js +13 -5
- package/lib/server/calculators/index.d.ts +4 -2
- package/lib/server/calculators/index.js +6 -4
- package/lib/server/collections/executions.js +2 -1
- package/lib/server/constants.d.ts +1 -0
- package/lib/server/constants.js +1 -0
- package/lib/server/extensions/assignees/actions.js +2 -3
- package/lib/server/extensions/assignees/collections/users_jobs.js +9 -1
- package/lib/server/index.d.ts +3 -4
- package/lib/server/index.js +21 -44
- package/lib/server/instructions/condition.js +1 -1
- package/lib/server/instructions/create.js +3 -1
- package/lib/server/instructions/delay.js +2 -3
- package/lib/server/instructions/destroy.js +3 -1
- package/lib/server/instructions/index.d.ts +3 -2
- package/lib/server/instructions/index.js +1 -1
- package/lib/server/instructions/prompt.js +2 -1
- package/lib/server/instructions/query.js +3 -1
- package/lib/server/instructions/request.d.ts +14 -0
- package/lib/server/instructions/request.js +154 -0
- package/lib/server/instructions/update.d.ts +1 -1
- package/lib/server/instructions/update.js +3 -1
- package/lib/server/migrations/20221129153547-calculation-variables.d.ts +5 -0
- package/lib/server/migrations/20221129153547-calculation-variables.js +116 -0
- package/lib/server/triggers/collection.js +5 -7
- package/lib/server/triggers/schedule.js +17 -6
- package/package.json +13 -8
|
@@ -7,9 +7,10 @@ export declare type Job = {
|
|
|
7
7
|
[key: string]: unknown;
|
|
8
8
|
} | null;
|
|
9
9
|
export declare type InstructionResult = Job | Promise<Job>;
|
|
10
|
+
export declare type Runner = (node: FlowNodeModel, input: any, processor: Processor) => InstructionResult;
|
|
10
11
|
export interface Instruction {
|
|
11
|
-
run
|
|
12
|
-
resume
|
|
12
|
+
run: Runner;
|
|
13
|
+
resume?: Runner;
|
|
13
14
|
}
|
|
14
15
|
declare type InstructionConstructor<T> = {
|
|
15
16
|
new (p: Plugin): T;
|
|
@@ -47,7 +47,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
47
47
|
|
|
48
48
|
function _default(plugin, more = {}) {
|
|
49
49
|
const instructions = plugin.instructions;
|
|
50
|
-
const natives = ['calculation', 'condition', 'parallel', 'delay', 'prompt', 'query', 'create', 'update', 'destroy'].reduce((result, key) => Object.assign(result, {
|
|
50
|
+
const natives = ['calculation', 'condition', 'parallel', 'delay', 'prompt', 'query', 'create', 'update', 'destroy', 'request'].reduce((result, key) => Object.assign(result, {
|
|
51
51
|
[key]: (0, _utils().requireModule)(_path().default.isAbsolute(key) ? key : _path().default.join(__dirname, key))
|
|
52
52
|
}), {});
|
|
53
53
|
|
|
@@ -86,7 +86,8 @@ class _default {
|
|
|
86
86
|
actionName = _context$action.actionName,
|
|
87
87
|
resourceName = _context$action.resourceName;
|
|
88
88
|
|
|
89
|
-
if (actionName === 'submit' && resourceName === 'jobs' &&
|
|
89
|
+
if (actionName === 'submit' && resourceName === 'jobs' // && this.middlewares.length
|
|
90
|
+
) {
|
|
90
91
|
return (0, _koaCompose().default)([loadJob, ..._this.middlewares])(context, next);
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -28,7 +28,9 @@ var _default = {
|
|
|
28
28
|
const repo = node.constructor.database.getRepository(collection);
|
|
29
29
|
const options = processor.getParsedValue(params);
|
|
30
30
|
const result = yield (multiple ? repo.find : repo.findOne).call(repo, _objectSpread(_objectSpread({}, options), {}, {
|
|
31
|
-
context:
|
|
31
|
+
context: {
|
|
32
|
+
executionId: processor.execution.id
|
|
33
|
+
},
|
|
32
34
|
transaction: processor.transaction
|
|
33
35
|
})); // NOTE: `toJSON()` to avoid getting undefined value from Proxied model instance (#380)
|
|
34
36
|
// e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Instruction } from './index';
|
|
3
|
+
export interface Header {
|
|
4
|
+
name: string;
|
|
5
|
+
value: any;
|
|
6
|
+
}
|
|
7
|
+
export declare type RequestConfig = Pick<AxiosRequestConfig, 'url' | 'method' | 'data' | 'timeout'> & {
|
|
8
|
+
headers: Array<Header>;
|
|
9
|
+
ignoreFail: boolean;
|
|
10
|
+
};
|
|
11
|
+
export default class implements Instruction {
|
|
12
|
+
run(node: any, input: any, processor: any): Promise<any>;
|
|
13
|
+
resume(node: any, job: any, processor: any): Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
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 _ejs() {
|
|
11
|
+
const data = require("ejs");
|
|
12
|
+
|
|
13
|
+
_ejs = function _ejs() {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _axios() {
|
|
21
|
+
const data = _interopRequireDefault(require("axios"));
|
|
22
|
+
|
|
23
|
+
_axios = function _axios() {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _lodash() {
|
|
31
|
+
const data = _interopRequireDefault(require("lodash"));
|
|
32
|
+
|
|
33
|
+
_lodash = function _lodash() {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
|
+
|
|
42
|
+
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); } }
|
|
43
|
+
|
|
44
|
+
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); }); }; }
|
|
45
|
+
|
|
46
|
+
function renderData(_x, _x2) {
|
|
47
|
+
return _renderData.apply(this, arguments);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _renderData() {
|
|
51
|
+
_renderData = _asyncToGenerator(function* (templateStr, vars) {
|
|
52
|
+
if (_lodash().default.isEmpty(templateStr)) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (0, _ejs().render)(templateStr, vars, {
|
|
57
|
+
async: true
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
return _renderData.apply(this, arguments);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function triggerResume(_x3, _x4, _x5, _x6) {
|
|
64
|
+
return _triggerResume.apply(this, arguments);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function _triggerResume() {
|
|
68
|
+
_triggerResume = _asyncToGenerator(function* (plugin, job, status, result) {
|
|
69
|
+
job.set('status', status);
|
|
70
|
+
job.set('result', result);
|
|
71
|
+
return plugin.resume(job);
|
|
72
|
+
});
|
|
73
|
+
return _triggerResume.apply(this, arguments);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class _default {
|
|
77
|
+
run(node, input, processor) {
|
|
78
|
+
return _asyncToGenerator(function* () {
|
|
79
|
+
const templateVars = {
|
|
80
|
+
node: processor.jobsMapByNodeId,
|
|
81
|
+
ctx: processor.execution.context
|
|
82
|
+
};
|
|
83
|
+
const requestConfig = node.config; // default headers
|
|
84
|
+
|
|
85
|
+
const headers = {
|
|
86
|
+
'Content-Type': 'application/json'
|
|
87
|
+
};
|
|
88
|
+
const _requestConfig$header = requestConfig.headers,
|
|
89
|
+
headerArr = _requestConfig$header === void 0 ? [] : _requestConfig$header,
|
|
90
|
+
_requestConfig$ignore = requestConfig.ignoreFail,
|
|
91
|
+
ignoreFail = _requestConfig$ignore === void 0 ? false : _requestConfig$ignore,
|
|
92
|
+
_requestConfig$method = requestConfig.method,
|
|
93
|
+
method = _requestConfig$method === void 0 ? 'POST' : _requestConfig$method,
|
|
94
|
+
_requestConfig$timeou = requestConfig.timeout,
|
|
95
|
+
timeout = _requestConfig$timeou === void 0 ? 5000 : _requestConfig$timeou;
|
|
96
|
+
headerArr.forEach(header => headers[header.name] = header.value);
|
|
97
|
+
let url, data;
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
url = yield renderData(requestConfig.url, templateVars);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.warn(e);
|
|
103
|
+
throw new Error(`ejs can't render url, please check url format!${e === null || e === void 0 ? void 0 : e.message}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
data = yield renderData(requestConfig.data, templateVars);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.warn(e);
|
|
110
|
+
throw new Error(`ejs can't render request data, please check request data format!${e === null || e === void 0 ? void 0 : e.message}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const job = yield processor.saveJob({
|
|
114
|
+
status: _constants.JOB_STATUS.PENDING,
|
|
115
|
+
nodeId: node.id
|
|
116
|
+
});
|
|
117
|
+
const plugin = processor.options.plugin;
|
|
118
|
+
|
|
119
|
+
_axios().default.request({
|
|
120
|
+
method,
|
|
121
|
+
timeout,
|
|
122
|
+
headers,
|
|
123
|
+
url,
|
|
124
|
+
data
|
|
125
|
+
}).then(resp => {
|
|
126
|
+
if (resp.status >= 200 && resp.status < 300) {
|
|
127
|
+
triggerResume(plugin, job, _constants.JOB_STATUS.RESOLVED, resp.data);
|
|
128
|
+
} else {
|
|
129
|
+
triggerResume(plugin, job, _constants.JOB_STATUS.REJECTED, resp);
|
|
130
|
+
}
|
|
131
|
+
}).catch(e => {
|
|
132
|
+
console.warn(e);
|
|
133
|
+
triggerResume(plugin, job, _constants.JOB_STATUS.REJECTED, e === null || e === void 0 ? void 0 : e.message);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return job;
|
|
137
|
+
})();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
resume(node, job, processor) {
|
|
141
|
+
return _asyncToGenerator(function* () {
|
|
142
|
+
const ignoreFail = node.config.ignoreFail;
|
|
143
|
+
|
|
144
|
+
if (ignoreFail) {
|
|
145
|
+
job.set('status', _constants.JOB_STATUS.RESOLVED);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return job;
|
|
149
|
+
})();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
exports.default = _default;
|
|
@@ -2,7 +2,7 @@ import FlowNodeModel from "../models/FlowNode";
|
|
|
2
2
|
import Processor from "../Processor";
|
|
3
3
|
declare const _default: {
|
|
4
4
|
run(node: FlowNodeModel, input: any, processor: Processor): Promise<{
|
|
5
|
-
result:
|
|
5
|
+
result: any;
|
|
6
6
|
status: number;
|
|
7
7
|
}>;
|
|
8
8
|
};
|
|
@@ -29,7 +29,9 @@ var _default = {
|
|
|
29
29
|
const repo = node.constructor.database.getRepository(collection);
|
|
30
30
|
const options = processor.getParsedValue(params);
|
|
31
31
|
const result = yield repo.update(_objectSpread(_objectSpread({}, options), {}, {
|
|
32
|
-
context:
|
|
32
|
+
context: {
|
|
33
|
+
executionId: processor.execution.id
|
|
34
|
+
},
|
|
33
35
|
transaction: processor.transaction
|
|
34
36
|
}));
|
|
35
37
|
return {
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _server() {
|
|
9
|
+
const data = require("@nocobase/server");
|
|
10
|
+
|
|
11
|
+
_server = function _server() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
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); } }
|
|
19
|
+
|
|
20
|
+
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); }); }; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
|
|
28
|
+
const VTypes = {
|
|
29
|
+
constant(operand) {
|
|
30
|
+
return operand.value;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
$jobsMapByNodeId({
|
|
34
|
+
options
|
|
35
|
+
}) {
|
|
36
|
+
const paths = [options.nodeId, options.path].filter(Boolean);
|
|
37
|
+
return paths ? `{{$jobsMapByNodeId.${paths.join('.')}}}` : null;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
$context({
|
|
41
|
+
options
|
|
42
|
+
}) {
|
|
43
|
+
return `{{$context.${options.path}}}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function migrateConfig(config) {
|
|
49
|
+
if (Array.isArray(config)) {
|
|
50
|
+
return config.map(item => migrateConfig(item));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof config !== 'object') {
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!config) {
|
|
58
|
+
return config;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (config.type && VTypes[config.type] && (config.options || config.value)) {
|
|
62
|
+
return VTypes[config.type](config);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return Object.keys(config).reduce((memo, key) => _objectSpread(_objectSpread({}, memo), {}, {
|
|
66
|
+
[key]: migrateConfig(config[key])
|
|
67
|
+
}), {});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class _default extends _server().Migration {
|
|
71
|
+
up() {
|
|
72
|
+
var _this = this;
|
|
73
|
+
|
|
74
|
+
return _asyncToGenerator(function* () {
|
|
75
|
+
const match = yield _this.app.version.satisfies('<=0.8.0-alpha.13');
|
|
76
|
+
|
|
77
|
+
if (!match) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const NodeRepo = _this.context.db.getRepository('flow_nodes');
|
|
82
|
+
|
|
83
|
+
yield _this.context.db.sequelize.transaction( /*#__PURE__*/function () {
|
|
84
|
+
var _ref = _asyncToGenerator(function* (transaction) {
|
|
85
|
+
const nodes = yield NodeRepo.find({
|
|
86
|
+
filter: {
|
|
87
|
+
type: {
|
|
88
|
+
$or: ['calculation', 'condition']
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
transaction
|
|
92
|
+
});
|
|
93
|
+
console.log('%d nodes need to be migrated.', nodes.length);
|
|
94
|
+
yield nodes.reduce((promise, node) => {
|
|
95
|
+
return node.update({
|
|
96
|
+
config: migrateConfig(node.config)
|
|
97
|
+
}, {
|
|
98
|
+
transaction
|
|
99
|
+
});
|
|
100
|
+
}, Promise.resolve());
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return function (_x) {
|
|
104
|
+
return _ref.apply(this, arguments);
|
|
105
|
+
};
|
|
106
|
+
}());
|
|
107
|
+
})();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
down() {
|
|
111
|
+
return _asyncToGenerator(function* () {})();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exports.default = _default;
|
|
@@ -62,10 +62,11 @@ function _handler() {
|
|
|
62
62
|
collectionName = _workflow$config3.collection,
|
|
63
63
|
condition = _workflow$config3.condition,
|
|
64
64
|
changed = _workflow$config3.changed;
|
|
65
|
-
const collection = data.constructor.database.getCollection(collectionName);
|
|
65
|
+
const collection = data.constructor.database.getCollection(collectionName);
|
|
66
|
+
const transaction = options.transaction,
|
|
67
|
+
context = options.context; // NOTE: if no configured fields changed, do not trigger
|
|
66
68
|
|
|
67
69
|
if (changed && changed.length && changed.filter(name => !['linkTo', 'hasOne', 'hasMany', 'belongsToMany'].includes(collection.getField(name).type)).every(name => !data.changedWithAssociations(getFieldRawName(collection, name)))) {
|
|
68
|
-
// TODO: temp comment out
|
|
69
70
|
return;
|
|
70
71
|
} // NOTE: if no configured condition match, do not trigger
|
|
71
72
|
|
|
@@ -75,8 +76,6 @@ function _handler() {
|
|
|
75
76
|
// const calculation = toCalculation(condition);
|
|
76
77
|
const repository = collection.repository,
|
|
77
78
|
model = collection.model;
|
|
78
|
-
const transaction = options.transaction,
|
|
79
|
-
context = options.context;
|
|
80
79
|
const count = yield repository.count({
|
|
81
80
|
filter: {
|
|
82
81
|
$and: [condition, {
|
|
@@ -92,11 +91,10 @@ function _handler() {
|
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
|
|
94
|
+
this.plugin.trigger(workflow, {
|
|
96
95
|
data: data.get()
|
|
97
96
|
}, {
|
|
98
|
-
context
|
|
99
|
-
transaction: options.transaction
|
|
97
|
+
context
|
|
100
98
|
});
|
|
101
99
|
});
|
|
102
100
|
return _handler.apply(this, arguments);
|
|
@@ -218,7 +218,7 @@ ScheduleModes.set(SCHEDULE_MODE.COLLECTION_FIELD, {
|
|
|
218
218
|
const startTime = getDataOptionTime(data, startsOn);
|
|
219
219
|
const endTime = getDataOptionTime(data, endsOn, -1);
|
|
220
220
|
|
|
221
|
-
if (!startTime
|
|
221
|
+
if (!startTime) {
|
|
222
222
|
return;
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -457,7 +457,9 @@ class ScheduleTrigger extends _.Trigger {
|
|
|
457
457
|
this.cacheCycle = 60000;
|
|
458
458
|
|
|
459
459
|
this.run = () => {
|
|
460
|
-
const now = new Date();
|
|
460
|
+
const now = new Date(); // 1001 to avoid 999
|
|
461
|
+
|
|
462
|
+
const nextInterval = 1001 - now.getMilliseconds();
|
|
461
463
|
now.setMilliseconds(0); // NOTE: trigger `onTick` for high interval jobs which are cached in last 1 min
|
|
462
464
|
|
|
463
465
|
this.onTick(now); // NOTE: reload when second match cache cycle
|
|
@@ -465,6 +467,8 @@ class ScheduleTrigger extends _.Trigger {
|
|
|
465
467
|
if (!(now.getTime() % this.cacheCycle)) {
|
|
466
468
|
this.reload();
|
|
467
469
|
}
|
|
470
|
+
|
|
471
|
+
this.timer = setTimeout(this.run, nextInterval);
|
|
468
472
|
};
|
|
469
473
|
|
|
470
474
|
plugin.app.on('beforeStop', () => {
|
|
@@ -481,10 +485,7 @@ class ScheduleTrigger extends _.Trigger {
|
|
|
481
485
|
|
|
482
486
|
const now = new Date(); // NOTE: assign to this.timer to avoid duplicated initialization
|
|
483
487
|
|
|
484
|
-
this.timer = setTimeout(
|
|
485
|
-
this.timer = setInterval(this.run, this.interval); // initially trigger
|
|
486
|
-
// this.onTick(now);
|
|
487
|
-
}, // NOTE:
|
|
488
|
+
this.timer = setTimeout(this.run, // NOTE:
|
|
488
489
|
// try to align to system time on each second starts,
|
|
489
490
|
// after at least 1 second initialized for anything to get ready.
|
|
490
491
|
// so jobs in 2 seconds will be missed at first start.
|
|
@@ -629,6 +630,11 @@ class ScheduleTrigger extends _.Trigger {
|
|
|
629
630
|
return _asyncToGenerator(function* () {
|
|
630
631
|
const mode = workflow.config.mode;
|
|
631
632
|
const modeHandlers = ScheduleModes.get(mode);
|
|
633
|
+
|
|
634
|
+
if (!modeHandlers) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
|
|
632
638
|
return modeHandlers.trigger.call(_this8, workflow, date);
|
|
633
639
|
})();
|
|
634
640
|
}
|
|
@@ -666,6 +672,11 @@ ScheduleTrigger.CacheRules = [({
|
|
|
666
672
|
}) => (config.limit ? allExecuted < config.limit : true) && config.startsOn, matchNext, function (workflow, now) {
|
|
667
673
|
const mode = workflow.config.mode;
|
|
668
674
|
const modeHandlers = ScheduleModes.get(mode);
|
|
675
|
+
|
|
676
|
+
if (!modeHandlers) {
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
|
|
669
680
|
return modeHandlers.shouldCache.call(this, workflow, now);
|
|
670
681
|
}];
|
|
671
682
|
ScheduleTrigger.TriggerRules = [({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-workflow",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-alpha.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"licenses": [
|
|
@@ -10,18 +10,23 @@
|
|
|
10
10
|
}
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@nocobase/actions": "0.8.
|
|
14
|
-
"@nocobase/client": "0.8.
|
|
15
|
-
"@nocobase/database": "0.8.
|
|
16
|
-
"@nocobase/server": "0.8.
|
|
17
|
-
"@nocobase/utils": "0.8.
|
|
13
|
+
"@nocobase/actions": "0.8.1-alpha.3",
|
|
14
|
+
"@nocobase/client": "0.8.1-alpha.3",
|
|
15
|
+
"@nocobase/database": "0.8.1-alpha.3",
|
|
16
|
+
"@nocobase/server": "0.8.1-alpha.3",
|
|
17
|
+
"@nocobase/utils": "0.8.1-alpha.3",
|
|
18
|
+
"antd": "4.22.8",
|
|
18
19
|
"classnames": "^2.3.1",
|
|
19
20
|
"cron-parser": "4.4.0",
|
|
21
|
+
"ejs": "^3.1.8",
|
|
20
22
|
"json-templates": "^4.2.0",
|
|
23
|
+
"moment": "^2.29.2",
|
|
24
|
+
"react-copy-to-clipboard": "^5.1.0",
|
|
21
25
|
"react-js-cron": "^1.4.0"
|
|
22
26
|
},
|
|
23
27
|
"devDependencies": {
|
|
24
|
-
"@nocobase/test": "0.8.
|
|
28
|
+
"@nocobase/test": "0.8.1-alpha.3",
|
|
29
|
+
"@types/ejs": "^3.1.1"
|
|
25
30
|
},
|
|
26
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "e03df3df5962b99d9fbf5b6e33fbe2b23f14f3d3"
|
|
27
32
|
}
|