@nocobase/plugin-workflow 2.1.0-beta.44 → 2.1.0-beta.46

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.
@@ -91,33 +91,38 @@ function getWorkflowExecutionLogMeta(workflow, processor) {
91
91
  }
92
92
  async function abortExecution(plugin, execution, options = {}) {
93
93
  const logger = plugin.getLogger(execution.workflowId);
94
- const ownTransaction = !options.transaction;
95
- const transaction = options.transaction ?? await plugin.useDataSourceTransaction("main", null, true);
94
+ const transaction = options.transaction ?? void 0;
96
95
  const ExecutionRepo = plugin.db.getRepository("executions");
97
96
  const JobRepo = plugin.db.getRepository("jobs");
98
97
  try {
99
- const lockedExecution = await ExecutionRepo.findOne({
100
- filterByTk: execution.id,
101
- transaction,
102
- lock: transaction.LOCK.UPDATE
103
- });
104
- if (!lockedExecution || lockedExecution.status !== import_constants.EXECUTION_STATUS.STARTED) {
105
- if (ownTransaction) {
106
- await transaction.commit();
98
+ const abortValues = {
99
+ status: import_constants.EXECUTION_STATUS.ABORTED,
100
+ ...options.reason ? {
101
+ reason: options.reason
102
+ } : {}
103
+ };
104
+ if (transaction) {
105
+ const lockedExecution = await ExecutionRepo.findOne({
106
+ filterByTk: execution.id,
107
+ transaction,
108
+ lock: transaction.LOCK.UPDATE
109
+ });
110
+ if (!lockedExecution || lockedExecution.status !== import_constants.EXECUTION_STATUS.STARTED) {
111
+ return false;
107
112
  }
108
- return false;
109
- }
110
- await lockedExecution.update(
111
- {
112
- status: import_constants.EXECUTION_STATUS.ABORTED,
113
- ...options.reason ? {
114
- reason: options.reason
115
- } : {}
116
- },
117
- {
118
- transaction
113
+ await lockedExecution.update(abortValues, { transaction });
114
+ } else {
115
+ const [affected] = await ExecutionRepo.model.update(abortValues, {
116
+ where: {
117
+ id: execution.id,
118
+ status: import_constants.EXECUTION_STATUS.STARTED
119
+ },
120
+ individualHooks: true
121
+ });
122
+ if (!affected) {
123
+ return false;
119
124
  }
120
- );
125
+ }
121
126
  const updated = await JobRepo.update({
122
127
  values: {
123
128
  status: import_constants.JOB_STATUS.ABORTED
@@ -139,24 +144,23 @@ async function abortExecution(plugin, execution, options = {}) {
139
144
  for (const child of childExecutions) {
140
145
  await abortExecution(plugin, child, { transaction, reason: import_constants.EXECUTION_REASON.PARENT_ABORTED });
141
146
  }
142
- afterTransactionCommit(transaction, () => {
147
+ const updateLocalState = () => {
143
148
  execution.set("status", import_constants.EXECUTION_STATUS.ABORTED);
144
149
  execution.set("reason", options.reason ?? null);
145
150
  plugin.timeoutManager.clear(execution.id);
146
151
  plugin.abortRunningExecution(execution.id, options.reason);
147
- });
152
+ };
153
+ if (transaction) {
154
+ afterTransactionCommit(transaction, updateLocalState);
155
+ } else {
156
+ updateLocalState();
157
+ }
148
158
  logger.info(`execution (${execution.id}) aborted`, {
149
159
  workflowId: execution.workflowId,
150
160
  pendingJobs: Array.isArray(updated) ? updated.length : updated
151
161
  });
152
- if (ownTransaction) {
153
- await transaction.commit();
154
- }
155
162
  return true;
156
163
  } catch (error) {
157
- if (ownTransaction && !transaction.finished) {
158
- await transaction.rollback();
159
- }
160
164
  throw error;
161
165
  }
162
166
  }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "A powerful BPM tool that provides foundational support for business automation, with the capability to extend unlimited triggers and nodes.",
7
7
  "description.zh-CN": "一个强大的 BPM 工具,为业务自动化提供基础支持,并且可任意扩展更多的触发器和节点。",
8
8
  "description.ru-RU": "Мощный инструмент BPM, обеспечивающий базовую поддержку автоматизации бизнес-процессов с возможностью неограниченного расширения триггеров и узлов.",
9
- "version": "2.1.0-beta.44",
9
+ "version": "2.1.0-beta.46",
10
10
  "license": "Apache-2.0",
11
11
  "main": "./dist/server/index.js",
12
12
  "homepage": "https://docs.nocobase.com/handbook/workflow",
@@ -49,7 +49,7 @@
49
49
  "@nocobase/test": "2.x",
50
50
  "@nocobase/utils": "2.x"
51
51
  },
52
- "gitHead": "540d4897b1696cc24c0754521b0b766978b4933c",
52
+ "gitHead": "91fd3ab238a5ff58735bbfca04a8cb05d233b0af",
53
53
  "keywords": [
54
54
  "Workflow"
55
55
  ]