@nocobase/plugin-workflow-delay 1.9.0-beta.5 → 1.9.0-beta.6

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.
@@ -11,8 +11,8 @@ module.exports = {
11
11
  "react": "18.2.0",
12
12
  "antd": "5.24.2",
13
13
  "@ant-design/icons": "5.6.1",
14
- "@nocobase/plugin-workflow": "1.9.0-beta.5",
15
- "@nocobase/client": "1.9.0-beta.5",
14
+ "@nocobase/plugin-workflow": "1.9.0-beta.6",
15
+ "@nocobase/client": "1.9.0-beta.6",
16
16
  "react-i18next": "11.18.6",
17
- "@nocobase/server": "1.9.0-beta.5"
17
+ "@nocobase/server": "1.9.0-beta.6"
18
18
  };
@@ -7,15 +7,15 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  /// <reference types="node" />
10
- import WorkflowPlugin, { Processor, Instruction } from '@nocobase/plugin-workflow';
10
+ import WorkflowPlugin, { Processor, Instruction, JobModel } from '@nocobase/plugin-workflow';
11
11
  export default class extends Instruction {
12
12
  workflow: WorkflowPlugin;
13
- timers: Map<number, NodeJS.Timeout>;
13
+ timers: Map<string, NodeJS.Timeout>;
14
14
  constructor(workflow: WorkflowPlugin);
15
15
  load: () => Promise<void>;
16
16
  unload: () => void;
17
17
  schedule(job: any): void;
18
- trigger(job: any): Promise<void>;
18
+ trigger(jobOrId: JobModel | string): Promise<void>;
19
19
  run(node: any, prevJob: any, processor: Processor): Promise<any>;
20
20
  resume(node: any, prevJob: any, processor: Processor): Promise<any>;
21
21
  }
@@ -74,25 +74,28 @@ class DelayInstruction_default extends import_plugin_workflow.Instruction {
74
74
  this.timers = /* @__PURE__ */ new Map();
75
75
  };
76
76
  schedule(job) {
77
- const now = /* @__PURE__ */ new Date();
78
- const createdAt = Date.parse(job.createdAt);
79
- const delay = createdAt + job.result - now.getTime();
77
+ const createdAt = new Date(job.createdAt).getTime();
78
+ const delay = createdAt + job.result - Date.now();
80
79
  if (delay > 0) {
81
- const trigger = this.trigger.bind(this, job);
82
- this.timers.set(job.id, setTimeout(trigger, delay));
80
+ const trigger = this.trigger.bind(this, job.id);
81
+ this.timers.set(job.id.toString(), setTimeout(trigger, delay));
83
82
  } else {
84
83
  this.trigger(job);
85
84
  }
86
85
  }
87
- async trigger(job) {
86
+ async trigger(jobOrId) {
87
+ const { model } = this.workflow.app.db.getCollection("jobs");
88
+ const job = jobOrId instanceof model ? jobOrId : await this.workflow.app.db.getRepository("jobs").findOne({ filterByTk: jobOrId });
88
89
  if (!job.execution) {
89
90
  job.execution = await job.getExecution();
90
91
  }
91
92
  if (job.execution.status === import_plugin_workflow.EXECUTION_STATUS.STARTED) {
92
93
  this.workflow.resume(job);
93
94
  }
94
- if (this.timers.get(job.id)) {
95
- this.timers.delete(job.id);
95
+ const idStr = job.id.toString();
96
+ if (this.timers.get(idStr)) {
97
+ clearTimeout(this.timers.get(idStr));
98
+ this.timers.delete(idStr);
96
99
  }
97
100
  }
98
101
  async run(node, prevJob, processor) {
@@ -104,8 +107,8 @@ class DelayInstruction_default extends import_plugin_workflow.Instruction {
104
107
  nodeKey: node.key,
105
108
  upstreamId: (prevJob == null ? void 0 : prevJob.id) ?? null
106
109
  });
107
- job.node = node;
108
110
  this.schedule(job);
111
+ processor.logger.debug(`delay node (${node.id}) will resume after ${duration}ms`);
109
112
  return null;
110
113
  }
111
114
  async resume(node, prevJob, processor) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流:延时节点",
5
5
  "description": "Could be used in workflow parallel branch for waiting other branches.",
6
6
  "description.zh-CN": "可用于工作流并行分支中等待其他分支执行完成。",
7
- "version": "1.9.0-beta.5",
7
+ "version": "1.9.0-beta.6",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/workflow-delay",
@@ -21,7 +21,7 @@
21
21
  "@nocobase/server": "1.x",
22
22
  "@nocobase/test": "1.x"
23
23
  },
24
- "gitHead": "9a61c60dd3db5af64244e82447309b0cb17aabb6",
24
+ "gitHead": "ada5e359a91135cb9baf605c04c5c380f067a046",
25
25
  "keywords": [
26
26
  "Workflow"
27
27
  ]