@nocobase/plugin-workflow 2.0.0-alpha.7 → 2.0.0-alpha.70
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/0b6813dae26ccf21.js +10 -0
- package/dist/client/{f68fbc145c3ddec3.js → 2076012783c998ad.js} +1 -1
- package/dist/client/59fcf22e646963ed.js +10 -0
- package/dist/client/AddNodeContext.d.ts +1 -0
- package/dist/client/Branch.d.ts +2 -0
- package/dist/client/NodeClipboardContext.d.ts +11 -0
- package/dist/client/NodeDragContext.d.ts +11 -0
- package/dist/client/RemoveNodeContext.d.ts +11 -0
- package/dist/client/WorkflowTasks.d.ts +3 -1
- package/dist/client/flows/triggerWorkflows.d.ts +15 -42
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +1 -1
- package/dist/client/models/NodeDetailsModel.d.ts +34 -0
- package/dist/client/models/NodeValueModel.d.ts +15 -0
- package/dist/client/models/TaskCardCommonItemModel.d.ts +14 -0
- package/dist/client/models/index.d.ts +11 -0
- package/dist/client/nodeVariableUtils.d.ts +14 -0
- package/dist/client/nodes/calculation.d.ts +7 -0
- package/dist/client/nodes/condition.d.ts +0 -3
- package/dist/client/nodes/create.d.ts +7 -0
- package/dist/client/nodes/index.d.ts +14 -0
- package/dist/client/nodes/multi-conditions.d.ts +57 -0
- package/dist/client/nodes/output.d.ts +53 -0
- package/dist/client/nodes/query.d.ts +7 -0
- package/dist/client/schemas/executions.d.ts +1 -1
- package/dist/client/style.d.ts +4 -0
- package/dist/client/variable.d.ts +1 -1
- package/dist/common/collections/executions.d.ts +1 -1
- package/dist/common/collections/executions.js +13 -1
- package/dist/common/collections/jobs.js +8 -0
- package/dist/externalVersion.js +12 -11
- package/dist/locale/de-DE.json +237 -188
- package/dist/locale/en-US.json +252 -188
- package/dist/locale/es-ES.json +245 -78
- package/dist/locale/fr-FR.json +245 -78
- package/dist/locale/hu-HU.json +266 -0
- package/dist/locale/id-ID.json +266 -0
- package/dist/locale/it-IT.json +236 -176
- package/dist/locale/ja-JP.json +241 -164
- package/dist/locale/ko-KR.json +267 -150
- package/dist/locale/nl-NL.json +264 -99
- package/dist/locale/pt-BR.json +245 -78
- package/dist/locale/ru-RU.json +250 -67
- package/dist/locale/tr-TR.json +246 -63
- package/dist/locale/uk-UA.json +265 -0
- package/dist/locale/vi-VN.json +266 -0
- package/dist/locale/zh-CN.json +257 -226
- package/dist/locale/zh-TW.json +265 -0
- package/dist/node_modules/cron-parser/package.json +1 -1
- package/dist/node_modules/lru-cache/package.json +1 -1
- package/dist/node_modules/nodejs-snowflake/package.json +1 -1
- package/dist/server/Dispatcher.d.ts +1 -3
- package/dist/server/Dispatcher.js +32 -31
- package/dist/server/Plugin.d.ts +3 -0
- package/dist/server/Plugin.js +61 -21
- package/dist/server/Processor.d.ts +9 -0
- package/dist/server/Processor.js +43 -13
- package/dist/server/actions/index.js +5 -0
- package/dist/server/actions/jobs.d.ts +9 -0
- package/dist/server/actions/jobs.js +64 -0
- package/dist/server/actions/nodes.d.ts +3 -0
- package/dist/server/actions/nodes.js +427 -17
- package/dist/server/instructions/ConditionInstruction.js +4 -1
- package/dist/server/instructions/MultiConditionsInstruction.d.ts +18 -0
- package/dist/server/instructions/MultiConditionsInstruction.js +118 -0
- package/dist/server/instructions/OutputInstruction.d.ts +21 -0
- package/dist/server/instructions/OutputInstruction.js +54 -0
- package/dist/server/instructions/index.d.ts +3 -1
- package/dist/server/repositories/WorkflowRepository.js +10 -2
- package/dist/server/triggers/CollectionTrigger.d.ts +3 -0
- package/dist/server/triggers/CollectionTrigger.js +31 -3
- package/dist/server/triggers/ScheduleTrigger/DateFieldScheduleTrigger.js +8 -0
- package/dist/server/triggers/index.d.ts +3 -1
- package/dist/server/types/Job.d.ts +1 -0
- package/package.json +5 -2
- package/dist/client/4985975bcaea35eb.js +0 -10
- package/dist/client/91bf4b18d5aad6a7.js +0 -10
package/dist/server/Plugin.js
CHANGED
|
@@ -36,6 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
37
|
var Plugin_exports = {};
|
|
38
38
|
__export(Plugin_exports, {
|
|
39
|
+
WORKER_JOB_WORKFLOW_PROCESS: () => WORKER_JOB_WORKFLOW_PROCESS,
|
|
39
40
|
default: () => PluginWorkflowServer
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(Plugin_exports);
|
|
@@ -54,11 +55,14 @@ var import_ScheduleTrigger = __toESM(require("./triggers/ScheduleTrigger"));
|
|
|
54
55
|
var import_CalculationInstruction = __toESM(require("./instructions/CalculationInstruction"));
|
|
55
56
|
var import_ConditionInstruction = __toESM(require("./instructions/ConditionInstruction"));
|
|
56
57
|
var import_EndInstruction = __toESM(require("./instructions/EndInstruction"));
|
|
58
|
+
var import_OutputInstruction = __toESM(require("./instructions/OutputInstruction"));
|
|
57
59
|
var import_CreateInstruction = __toESM(require("./instructions/CreateInstruction"));
|
|
58
60
|
var import_DestroyInstruction = __toESM(require("./instructions/DestroyInstruction"));
|
|
59
61
|
var import_QueryInstruction = __toESM(require("./instructions/QueryInstruction"));
|
|
60
62
|
var import_UpdateInstruction = __toESM(require("./instructions/UpdateInstruction"));
|
|
63
|
+
var import_MultiConditionsInstruction = __toESM(require("./instructions/MultiConditionsInstruction"));
|
|
61
64
|
var import_WorkflowRepository = __toESM(require("./repositories/WorkflowRepository"));
|
|
65
|
+
const WORKER_JOB_WORKFLOW_PROCESS = "workflow:process";
|
|
62
66
|
class PluginWorkflowServer extends import_server.Plugin {
|
|
63
67
|
instructions = new import_utils.Registry();
|
|
64
68
|
triggers = new import_utils.Registry();
|
|
@@ -66,6 +70,9 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
66
70
|
enabledCache = /* @__PURE__ */ new Map();
|
|
67
71
|
snowflake;
|
|
68
72
|
dispatcher = new import_Dispatcher.default(this);
|
|
73
|
+
get channelPendingExecution() {
|
|
74
|
+
return `${this.name}.pendingExecution`;
|
|
75
|
+
}
|
|
69
76
|
loggerCache;
|
|
70
77
|
meter = null;
|
|
71
78
|
checker = null;
|
|
@@ -138,7 +145,6 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
138
145
|
// * add all hooks for enabled workflows
|
|
139
146
|
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
|
|
140
147
|
onAfterStart = async () => {
|
|
141
|
-
this.dispatcher.setReady(true);
|
|
142
148
|
const collection = this.db.getCollection("workflows");
|
|
143
149
|
const workflows = await collection.repository.find({
|
|
144
150
|
appends: ["versionStats"]
|
|
@@ -165,19 +171,20 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
165
171
|
this.app.logger.info("workflow:dispatch");
|
|
166
172
|
this.dispatcher.dispatch();
|
|
167
173
|
});
|
|
174
|
+
this.dispatcher.setReady(true);
|
|
168
175
|
this.getLogger("dispatcher").info("(starting) check for queueing executions");
|
|
169
176
|
this.dispatcher.dispatch();
|
|
170
|
-
this.dispatcher.setReady(true);
|
|
171
177
|
};
|
|
172
178
|
onBeforeStop = async () => {
|
|
179
|
+
if (this.checker) {
|
|
180
|
+
clearInterval(this.checker);
|
|
181
|
+
}
|
|
182
|
+
await this.dispatcher.beforeStop();
|
|
173
183
|
this.app.logger.info(`stopping workflow plugin before app (${this.app.name}) shutdown...`);
|
|
174
184
|
for (const workflow of this.enabledCache.values()) {
|
|
175
185
|
this.toggle(workflow, false, { silent: true });
|
|
176
186
|
}
|
|
177
|
-
|
|
178
|
-
if (this.checker) {
|
|
179
|
-
clearInterval(this.checker);
|
|
180
|
-
}
|
|
187
|
+
this.app.eventQueue.unsubscribe(this.channelPendingExecution);
|
|
181
188
|
this.loggerCache.clear();
|
|
182
189
|
};
|
|
183
190
|
async handleSyncMessage(message) {
|
|
@@ -202,13 +209,16 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
202
209
|
}
|
|
203
210
|
}
|
|
204
211
|
}
|
|
212
|
+
serving() {
|
|
213
|
+
return this.app.serving(WORKER_JOB_WORKFLOW_PROCESS);
|
|
214
|
+
}
|
|
205
215
|
/**
|
|
206
216
|
* @experimental
|
|
207
217
|
*/
|
|
208
218
|
getLogger(workflowId = "dispatcher") {
|
|
209
219
|
const now = /* @__PURE__ */ new Date();
|
|
210
220
|
const date = `${now.getFullYear()}-${`0${now.getMonth() + 1}`.slice(-2)}-${`0${now.getDate()}`.slice(-2)}`;
|
|
211
|
-
const key = `${date}-${workflowId}
|
|
221
|
+
const key = `${date}-${workflowId}`;
|
|
212
222
|
if (this.loggerCache.has(key)) {
|
|
213
223
|
return this.loggerCache.get(key);
|
|
214
224
|
}
|
|
@@ -259,7 +269,9 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
259
269
|
initInstructions(more = {}) {
|
|
260
270
|
this.registerInstruction("calculation", import_CalculationInstruction.default);
|
|
261
271
|
this.registerInstruction("condition", import_ConditionInstruction.default);
|
|
272
|
+
this.registerInstruction("multi-conditions", import_MultiConditionsInstruction.default);
|
|
262
273
|
this.registerInstruction("end", import_EndInstruction.default);
|
|
274
|
+
this.registerInstruction("output", import_OutputInstruction.default);
|
|
263
275
|
this.registerInstruction("create", import_CreateInstruction.default);
|
|
264
276
|
this.registerInstruction("destroy", import_DestroyInstruction.default);
|
|
265
277
|
this.registerInstruction("query", import_QueryInstruction.default);
|
|
@@ -277,11 +289,8 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
277
289
|
filter: { name: this.name }
|
|
278
290
|
});
|
|
279
291
|
this.snowflake = new import_nodejs_snowflake.Snowflake({
|
|
280
|
-
custom_epoch: pluginRecord == null ? void 0 : pluginRecord.createdAt.getTime()
|
|
281
|
-
|
|
282
|
-
this.app.backgroundJobManager.subscribe(`${this.name}.pendingExecution`, {
|
|
283
|
-
idle: () => this.app.serving(import_Dispatcher.WORKER_JOB_WORKFLOW_PROCESS) && this.dispatcher.idle,
|
|
284
|
-
process: this.dispatcher.onQueueExecution
|
|
292
|
+
custom_epoch: pluginRecord == null ? void 0 : pluginRecord.createdAt.getTime(),
|
|
293
|
+
instance_id: this.app.instanceId
|
|
285
294
|
});
|
|
286
295
|
}
|
|
287
296
|
/**
|
|
@@ -293,18 +302,30 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
293
302
|
this.initTriggers(options.triggers);
|
|
294
303
|
this.initInstructions(options.instructions);
|
|
295
304
|
(0, import_functions.default)(this, options.functions);
|
|
305
|
+
this.functions.register("instanceId", () => this.app.instanceId);
|
|
306
|
+
this.functions.register("epoch", () => 1605024e3);
|
|
307
|
+
this.functions.register("genSnowflakeId", () => this.app.snowflakeIdGenerator.generate());
|
|
296
308
|
this.loggerCache = new import_lru_cache.default({
|
|
297
309
|
max: 20,
|
|
298
310
|
updateAgeOnGet: true,
|
|
299
311
|
dispose(logger) {
|
|
300
|
-
logger
|
|
312
|
+
const cachedLogger = logger;
|
|
313
|
+
if (!cachedLogger) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
cachedLogger.silent = true;
|
|
317
|
+
if (typeof cachedLogger.close === "function") {
|
|
318
|
+
cachedLogger.close();
|
|
319
|
+
}
|
|
301
320
|
}
|
|
302
321
|
});
|
|
303
322
|
this.meter = this.app.telemetry.metric.getMeter();
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
323
|
+
if (this.meter) {
|
|
324
|
+
const counter = this.meter.createObservableGauge("workflow.events.counter");
|
|
325
|
+
counter.addCallback((result) => {
|
|
326
|
+
result.observe(this.dispatcher.getEventsCount());
|
|
327
|
+
});
|
|
328
|
+
}
|
|
308
329
|
this.app.acl.registerSnippet({
|
|
309
330
|
name: `pm.${this.name}.workflows`,
|
|
310
331
|
actions: [
|
|
@@ -316,6 +337,9 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
316
337
|
"executions:destroy",
|
|
317
338
|
"flow_nodes:update",
|
|
318
339
|
"flow_nodes:destroy",
|
|
340
|
+
"flow_nodes:destroyBranch",
|
|
341
|
+
"flow_nodes:duplicate",
|
|
342
|
+
"flow_nodes:move",
|
|
319
343
|
"flow_nodes:test",
|
|
320
344
|
"jobs:get",
|
|
321
345
|
"workflowCategories:*"
|
|
@@ -333,12 +357,18 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
333
357
|
db.on("workflows.afterDestroy", this.onAfterDestroy);
|
|
334
358
|
this.app.on("afterStart", this.onAfterStart);
|
|
335
359
|
this.app.on("beforeStop", this.onBeforeStop);
|
|
360
|
+
this.app.eventQueue.subscribe(this.channelPendingExecution, {
|
|
361
|
+
idle: () => this.serving() && this.dispatcher.idle,
|
|
362
|
+
process: this.dispatcher.onQueueExecution
|
|
363
|
+
});
|
|
336
364
|
}
|
|
337
365
|
toggle(workflow, enable, { silent, transaction } = {}) {
|
|
338
366
|
const type = workflow.get("type");
|
|
339
367
|
const trigger = this.triggers.get(type);
|
|
340
368
|
if (!trigger) {
|
|
341
|
-
this.getLogger(workflow.id).error(`trigger type ${workflow.type} of workflow ${workflow.id} is not implemented
|
|
369
|
+
this.getLogger(workflow.id).error(`trigger type ${workflow.type} of workflow ${workflow.id} is not implemented`, {
|
|
370
|
+
workflowId: workflow.id
|
|
371
|
+
});
|
|
342
372
|
return;
|
|
343
373
|
}
|
|
344
374
|
const next = enable ?? workflow.get("enabled");
|
|
@@ -346,14 +376,20 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
346
376
|
const prev = workflow.previous();
|
|
347
377
|
if (prev.config) {
|
|
348
378
|
trigger.off({ ...workflow.get(), ...prev });
|
|
349
|
-
this.getLogger(workflow.id).info(`toggle OFF workflow ${workflow.id} based on configuration before updated
|
|
379
|
+
this.getLogger(workflow.id).info(`toggle OFF workflow ${workflow.id} based on configuration before updated`, {
|
|
380
|
+
workflowId: workflow.id
|
|
381
|
+
});
|
|
350
382
|
}
|
|
351
383
|
trigger.on(workflow);
|
|
352
|
-
this.getLogger(workflow.id).info(`toggle ON workflow ${workflow.id}
|
|
384
|
+
this.getLogger(workflow.id).info(`toggle ON workflow ${workflow.id}`, {
|
|
385
|
+
workflowId: workflow.id
|
|
386
|
+
});
|
|
353
387
|
this.enabledCache.set(workflow.id, workflow);
|
|
354
388
|
} else {
|
|
355
389
|
trigger.off(workflow);
|
|
356
|
-
this.getLogger(workflow.id).info(`toggle OFF workflow ${workflow.id}
|
|
390
|
+
this.getLogger(workflow.id).info(`toggle OFF workflow ${workflow.id}`, {
|
|
391
|
+
workflowId: workflow.id
|
|
392
|
+
});
|
|
357
393
|
this.enabledCache.delete(workflow.id);
|
|
358
394
|
}
|
|
359
395
|
if (!silent) {
|
|
@@ -453,3 +489,7 @@ class PluginWorkflowServer extends import_server.Plugin {
|
|
|
453
489
|
}
|
|
454
490
|
}
|
|
455
491
|
}
|
|
492
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
493
|
+
0 && (module.exports = {
|
|
494
|
+
WORKER_JOB_WORKFLOW_PROCESS
|
|
495
|
+
});
|
|
@@ -96,6 +96,15 @@ export default class Processor {
|
|
|
96
96
|
* @experimental
|
|
97
97
|
*/
|
|
98
98
|
getScope(sourceNodeId?: number | string, includeSelfScope?: boolean): {
|
|
99
|
+
ctx: {
|
|
100
|
+
$context: any;
|
|
101
|
+
$jobsMapByNodeKey: {
|
|
102
|
+
[key: string]: any;
|
|
103
|
+
};
|
|
104
|
+
$system: {};
|
|
105
|
+
$scopes: {};
|
|
106
|
+
$env: {};
|
|
107
|
+
};
|
|
99
108
|
$context: any;
|
|
100
109
|
$jobsMapByNodeKey: {
|
|
101
110
|
[key: string]: any;
|
package/dist/server/Processor.js
CHANGED
|
@@ -102,11 +102,15 @@ class Processor {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
makeJobs(jobs) {
|
|
105
|
-
|
|
105
|
+
for (const job of jobs) {
|
|
106
106
|
const node = this.nodesMap.get(job.nodeId);
|
|
107
|
+
if (!node) {
|
|
108
|
+
this.logger.warn(`node (#${job.nodeId}) not found for job (#${job.id}), this will lead to unexpected error`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
107
111
|
this.jobsMapByNodeKey[node.key] = job;
|
|
108
112
|
this.jobResultsMapByNodeKey[node.key] = job.result;
|
|
109
|
-
}
|
|
113
|
+
}
|
|
110
114
|
}
|
|
111
115
|
async prepare() {
|
|
112
116
|
const {
|
|
@@ -144,7 +148,9 @@ class Processor {
|
|
|
144
148
|
async start() {
|
|
145
149
|
const { execution } = this;
|
|
146
150
|
if (execution.status) {
|
|
147
|
-
this.logger.warn(`execution was ended with status ${execution.status} before, could not be started again
|
|
151
|
+
this.logger.warn(`execution was ended with status ${execution.status} before, could not be started again`, {
|
|
152
|
+
workflowId: execution.workflowId
|
|
153
|
+
});
|
|
148
154
|
return;
|
|
149
155
|
}
|
|
150
156
|
await this.prepare();
|
|
@@ -158,7 +164,9 @@ class Processor {
|
|
|
158
164
|
async resume(job) {
|
|
159
165
|
const { execution } = this;
|
|
160
166
|
if (execution.status) {
|
|
161
|
-
this.logger.warn(`execution was ended with status ${execution.status} before, could not be resumed
|
|
167
|
+
this.logger.warn(`execution was ended with status ${execution.status} before, could not be resumed`, {
|
|
168
|
+
workflowId: execution.workflowId
|
|
169
|
+
});
|
|
162
170
|
return;
|
|
163
171
|
}
|
|
164
172
|
await this.prepare();
|
|
@@ -168,7 +176,7 @@ class Processor {
|
|
|
168
176
|
async exec(instruction, node, prevJob) {
|
|
169
177
|
let job;
|
|
170
178
|
try {
|
|
171
|
-
this.logger.debug(`config of node`, { data: node.config });
|
|
179
|
+
this.logger.debug(`config of node`, { data: node.config, workflowId: node.workflowId });
|
|
172
180
|
job = await instruction(node, prevJob, this);
|
|
173
181
|
if (job === null) {
|
|
174
182
|
return this.exit();
|
|
@@ -179,7 +187,7 @@ class Processor {
|
|
|
179
187
|
} catch (err) {
|
|
180
188
|
this.logger.error(
|
|
181
189
|
`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id}) failed: `,
|
|
182
|
-
err
|
|
190
|
+
{ error: err, workflowId: node.workflowId }
|
|
183
191
|
);
|
|
184
192
|
job = {
|
|
185
193
|
result: err instanceof Error ? {
|
|
@@ -199,7 +207,10 @@ class Processor {
|
|
|
199
207
|
}
|
|
200
208
|
const savedJob = this.saveJob(job);
|
|
201
209
|
this.logger.info(
|
|
202
|
-
`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id}) finished as status: ${savedJob.status}
|
|
210
|
+
`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id}) finished as status: ${savedJob.status}`,
|
|
211
|
+
{
|
|
212
|
+
workflowId: node.workflowId
|
|
213
|
+
}
|
|
203
214
|
);
|
|
204
215
|
this.logger.debug(`result of node`, { data: savedJob.result });
|
|
205
216
|
if (savedJob.status === import_constants.JOB_STATUS.RESOLVED && node.downstream) {
|
|
@@ -217,7 +228,9 @@ class Processor {
|
|
|
217
228
|
if (typeof instruction.run !== "function") {
|
|
218
229
|
return Promise.reject(new Error("`run` should be implemented for customized execution of the node"));
|
|
219
230
|
}
|
|
220
|
-
this.logger.info(`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id})
|
|
231
|
+
this.logger.info(`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id})`, {
|
|
232
|
+
workflowId: node.workflowId
|
|
233
|
+
});
|
|
221
234
|
return this.exec(instruction.run.bind(instruction), node, input);
|
|
222
235
|
}
|
|
223
236
|
// parent node should take over the control
|
|
@@ -225,7 +238,9 @@ class Processor {
|
|
|
225
238
|
this.logger.debug(`branch ended at node (${node.id})`);
|
|
226
239
|
const parentNode = this.findBranchParentNode(node);
|
|
227
240
|
if (parentNode) {
|
|
228
|
-
this.logger.debug(`not on main, recall to parent entry node (${node.id})})
|
|
241
|
+
this.logger.debug(`not on main, recall to parent entry node (${node.id})})`, {
|
|
242
|
+
workflowId: node.workflowId
|
|
243
|
+
});
|
|
229
244
|
await this.recall(parentNode, job);
|
|
230
245
|
return null;
|
|
231
246
|
}
|
|
@@ -242,7 +257,9 @@ class Processor {
|
|
|
242
257
|
new Error(`"resume" method should be implemented for [${node.type}] instruction of node (#${node.id})`)
|
|
243
258
|
);
|
|
244
259
|
}
|
|
245
|
-
this.logger.info(`execution (${this.execution.id}) resume instruction [${node.type}] for node (${node.id})
|
|
260
|
+
this.logger.info(`execution (${this.execution.id}) resume instruction [${node.type}] for node (${node.id})`, {
|
|
261
|
+
workflowId: node.workflowId
|
|
262
|
+
});
|
|
246
263
|
return this.exec(instruction.resume.bind(instruction), node, job);
|
|
247
264
|
}
|
|
248
265
|
async exit(s) {
|
|
@@ -261,6 +278,10 @@ class Processor {
|
|
|
261
278
|
changes.push([`status`, job.status]);
|
|
262
279
|
job.changed("status", false);
|
|
263
280
|
}
|
|
281
|
+
if (job.changed("meta")) {
|
|
282
|
+
changes.push([`meta`, JSON.stringify(job.meta ?? null)]);
|
|
283
|
+
job.changed("meta", false);
|
|
284
|
+
}
|
|
264
285
|
if (job.changed("result")) {
|
|
265
286
|
changes.push([`result`, JSON.stringify(job.result ?? null)]);
|
|
266
287
|
job.changed("result", false);
|
|
@@ -295,7 +316,9 @@ class Processor {
|
|
|
295
316
|
if (this.mainTransaction && this.mainTransaction !== this.transaction) {
|
|
296
317
|
await this.mainTransaction.commit();
|
|
297
318
|
}
|
|
298
|
-
this.logger.info(`execution (${this.execution.id}) exiting with status ${this.execution.status}
|
|
319
|
+
this.logger.info(`execution (${this.execution.id}) exiting with status ${this.execution.status}`, {
|
|
320
|
+
workflowId: this.execution.workflowId
|
|
321
|
+
});
|
|
299
322
|
return null;
|
|
300
323
|
}
|
|
301
324
|
/**
|
|
@@ -326,7 +349,9 @@ class Processor {
|
|
|
326
349
|
this.lastSavedJob = job;
|
|
327
350
|
this.jobsMapByNodeKey[job.nodeKey] = job;
|
|
328
351
|
this.jobResultsMapByNodeKey[job.nodeKey] = job.result;
|
|
329
|
-
this.logger.debug(`job added to save list: ${JSON.stringify(job)}
|
|
352
|
+
this.logger.debug(`job added to save list: ${JSON.stringify(job)}`, {
|
|
353
|
+
workflowId: this.execution.workflowId
|
|
354
|
+
});
|
|
330
355
|
return job;
|
|
331
356
|
}
|
|
332
357
|
/**
|
|
@@ -414,13 +439,18 @@ class Processor {
|
|
|
414
439
|
$scopes[n.id] = $scopes[n.key] = instruction.getScope(n, this.jobResultsMapByNodeKey[n.key], this);
|
|
415
440
|
}
|
|
416
441
|
}
|
|
417
|
-
|
|
442
|
+
const scopes = {
|
|
418
443
|
$context: this.execution.context,
|
|
419
444
|
$jobsMapByNodeKey: this.jobResultsMapByNodeKey,
|
|
420
445
|
$system: systemFns,
|
|
421
446
|
$scopes,
|
|
422
447
|
$env: this.options.plugin.app.environment.getVariables()
|
|
423
448
|
};
|
|
449
|
+
return {
|
|
450
|
+
...scopes,
|
|
451
|
+
ctx: scopes
|
|
452
|
+
// 2.0
|
|
453
|
+
};
|
|
424
454
|
}
|
|
425
455
|
/**
|
|
426
456
|
* @experimental
|
|
@@ -41,6 +41,7 @@ __export(actions_exports, {
|
|
|
41
41
|
module.exports = __toCommonJS(actions_exports);
|
|
42
42
|
var workflows = __toESM(require("./workflows"));
|
|
43
43
|
var nodes = __toESM(require("./nodes"));
|
|
44
|
+
var jobs = __toESM(require("./jobs"));
|
|
44
45
|
var executions = __toESM(require("./executions"));
|
|
45
46
|
var userWorkflowTasks = __toESM(require("./userWorkflowTasks"));
|
|
46
47
|
function make(name, mod) {
|
|
@@ -61,8 +62,12 @@ function actions_default({ app }) {
|
|
|
61
62
|
...make("flow_nodes", {
|
|
62
63
|
update: nodes.update,
|
|
63
64
|
destroy: nodes.destroy,
|
|
65
|
+
destroyBranch: nodes.destroyBranch,
|
|
66
|
+
duplicate: nodes.duplicate,
|
|
67
|
+
move: nodes.move,
|
|
64
68
|
test: nodes.test
|
|
65
69
|
}),
|
|
70
|
+
...make("jobs", jobs),
|
|
66
71
|
...make("executions", executions),
|
|
67
72
|
...make("userWorkflowTasks", userWorkflowTasks)
|
|
68
73
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resume(context: any, next: any): Promise<any>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var jobs_exports = {};
|
|
38
|
+
__export(jobs_exports, {
|
|
39
|
+
resume: () => resume
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(jobs_exports);
|
|
42
|
+
var import_actions = require("@nocobase/actions");
|
|
43
|
+
var import_Plugin = __toESM(require("../Plugin"));
|
|
44
|
+
async function resume(context, next) {
|
|
45
|
+
const repository = import_actions.utils.getRepositoryFromParams(context);
|
|
46
|
+
const workflowPlugin = context.app.pm.get(import_Plugin.default);
|
|
47
|
+
const { filterByTk, values = {} } = context.action.params;
|
|
48
|
+
const job = await repository.findOne({
|
|
49
|
+
filterByTk
|
|
50
|
+
});
|
|
51
|
+
if (!job) {
|
|
52
|
+
return context.throw(404, "Job not found");
|
|
53
|
+
}
|
|
54
|
+
workflowPlugin.getLogger(job.workflowId).warn(`Resuming job #${job.id}...`);
|
|
55
|
+
await job.update(values);
|
|
56
|
+
context.body = job;
|
|
57
|
+
context.status = 202;
|
|
58
|
+
await next();
|
|
59
|
+
workflowPlugin.resume(job);
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
resume
|
|
64
|
+
});
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Context } from '@nocobase/actions';
|
|
10
10
|
export declare function create(context: Context, next: any): Promise<void>;
|
|
11
|
+
export declare function duplicate(context: Context, next: any): Promise<void>;
|
|
11
12
|
export declare function destroy(context: Context, next: any): Promise<void>;
|
|
13
|
+
export declare function destroyBranch(context: Context, next: any): Promise<void>;
|
|
14
|
+
export declare function move(context: Context, next: any): Promise<void>;
|
|
12
15
|
export declare function update(context: Context, next: any): Promise<void>;
|
|
13
16
|
export declare function test(context: Context, next: any): Promise<void>;
|