From 80a685f8bf648121c76e7639497f7da259093354 Mon Sep 17 00:00:00 2001 From: Junyi Date: Sun, 22 May 2022 19:47:15 +0800 Subject: [PATCH] refactor(plugin-workflow): change column type of executed from boolean to integer (#411) --- .../plugins/workflow/src/__tests__/execution.test.ts | 2 +- .../plugins/workflow/src/collections/workflows.ts | 12 ++---------- packages/plugins/workflow/src/models/Workflow.ts | 12 ++++++------ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/plugins/workflow/src/__tests__/execution.test.ts b/packages/plugins/workflow/src/__tests__/execution.test.ts index 7d19bfe21..f0f4e4f4a 100644 --- a/packages/plugins/workflow/src/__tests__/execution.test.ts +++ b/packages/plugins/workflow/src/__tests__/execution.test.ts @@ -3,7 +3,7 @@ import Database from '@nocobase/database'; import { getApp } from '.'; import { BRANCH_INDEX, EXECUTION_STATUS, JOB_STATUS } from '../constants'; -jest.setTimeout(300000); + describe('execution', () => { let app: Application; diff --git a/packages/plugins/workflow/src/collections/workflows.ts b/packages/plugins/workflow/src/collections/workflows.ts index 406b92480..22a6b09c8 100644 --- a/packages/plugins/workflow/src/collections/workflows.ts +++ b/packages/plugins/workflow/src/collections/workflows.ts @@ -10,34 +10,29 @@ export default { type: 'uid' }, { - interface: 'string', type: 'string', name: 'title', title: '工作流名称', required: true }, { - interface: 'boolean', type: 'boolean', name: 'enabled', title: '启用', defaultValue: false }, { - interface: 'textarea', type: 'text', name: 'description', title: '描述' }, { - interface: 'select', type: 'string', title: '触发方式', name: 'type', required: true }, { - interface: 'json', type: 'jsonb', title: '触发配置', name: 'config', @@ -45,30 +40,27 @@ export default { defaultValue: {} }, { - interface: 'boolean', type: 'boolean', title: '使用事务', name: 'useTransaction', defaultValue: true }, { - interface: 'linkTo', type: 'hasMany', name: 'nodes', target: 'flow_nodes', title: '流程节点' }, { - interface: 'linkTo', type: 'hasMany', name: 'executions', target: 'executions', title: '触发执行' }, { - type: 'boolean', + type: 'integer', name: 'executed', - defaultValue: false + defaultValue: 0 }, { type: 'boolean', diff --git a/packages/plugins/workflow/src/models/Workflow.ts b/packages/plugins/workflow/src/models/Workflow.ts index 77d422562..38e81e00f 100644 --- a/packages/plugins/workflow/src/models/Workflow.ts +++ b/packages/plugins/workflow/src/models/Workflow.ts @@ -15,7 +15,7 @@ export default class WorkflowModel extends Model { declare type: string; declare config: any; declare useTransaction: boolean; - declare executed: boolean; + declare executed: number; declare createdAt: Date; declare updatedAt: Date; @@ -68,15 +68,15 @@ export default class WorkflowModel extends Model { transaction: transaction.id }, { transaction }); + const executed = await this.countExecutions({ transaction }); + + // NOTE: not to trigger afterUpdate hook here + await this.update({ executed }, { transaction, hooks: false }); + execution.workflow = this; await execution.start({ transaction }); - if (!this.executed) { - // NOTE: not to trigger afterUpdate hook here - await this.update({ executed: true }, { transaction, hooks: false }); - } - // @ts-ignore if (transaction && (!options.transaction || options.transaction.finished)) { await transaction.commit();