refactor(plugin-workflow): change column type of executed from boolean to integer (#411)

This commit is contained in:
Junyi 2022-05-22 19:47:15 +08:00 committed by GitHub
parent 19ee42257e
commit 80a685f8bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 17 deletions

View File

@ -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;

View File

@ -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',

View File

@ -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();