refactor(plugin-workflow): change column type of executed from boolean to integer (#411)
This commit is contained in:
parent
19ee42257e
commit
80a685f8bf
@ -3,7 +3,7 @@ import Database from '@nocobase/database';
|
|||||||
import { getApp } from '.';
|
import { getApp } from '.';
|
||||||
import { BRANCH_INDEX, EXECUTION_STATUS, JOB_STATUS } from '../constants';
|
import { BRANCH_INDEX, EXECUTION_STATUS, JOB_STATUS } from '../constants';
|
||||||
|
|
||||||
jest.setTimeout(300000);
|
|
||||||
|
|
||||||
describe('execution', () => {
|
describe('execution', () => {
|
||||||
let app: Application;
|
let app: Application;
|
||||||
|
@ -10,34 +10,29 @@ export default {
|
|||||||
type: 'uid'
|
type: 'uid'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'string',
|
|
||||||
type: 'string',
|
type: 'string',
|
||||||
name: 'title',
|
name: 'title',
|
||||||
title: '工作流名称',
|
title: '工作流名称',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'boolean',
|
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
name: 'enabled',
|
name: 'enabled',
|
||||||
title: '启用',
|
title: '启用',
|
||||||
defaultValue: false
|
defaultValue: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'textarea',
|
|
||||||
type: 'text',
|
type: 'text',
|
||||||
name: 'description',
|
name: 'description',
|
||||||
title: '描述'
|
title: '描述'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'select',
|
|
||||||
type: 'string',
|
type: 'string',
|
||||||
title: '触发方式',
|
title: '触发方式',
|
||||||
name: 'type',
|
name: 'type',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'json',
|
|
||||||
type: 'jsonb',
|
type: 'jsonb',
|
||||||
title: '触发配置',
|
title: '触发配置',
|
||||||
name: 'config',
|
name: 'config',
|
||||||
@ -45,30 +40,27 @@ export default {
|
|||||||
defaultValue: {}
|
defaultValue: {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'boolean',
|
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
title: '使用事务',
|
title: '使用事务',
|
||||||
name: 'useTransaction',
|
name: 'useTransaction',
|
||||||
defaultValue: true
|
defaultValue: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'linkTo',
|
|
||||||
type: 'hasMany',
|
type: 'hasMany',
|
||||||
name: 'nodes',
|
name: 'nodes',
|
||||||
target: 'flow_nodes',
|
target: 'flow_nodes',
|
||||||
title: '流程节点'
|
title: '流程节点'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
interface: 'linkTo',
|
|
||||||
type: 'hasMany',
|
type: 'hasMany',
|
||||||
name: 'executions',
|
name: 'executions',
|
||||||
target: 'executions',
|
target: 'executions',
|
||||||
title: '触发执行'
|
title: '触发执行'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'boolean',
|
type: 'integer',
|
||||||
name: 'executed',
|
name: 'executed',
|
||||||
defaultValue: false
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
@ -15,7 +15,7 @@ export default class WorkflowModel extends Model {
|
|||||||
declare type: string;
|
declare type: string;
|
||||||
declare config: any;
|
declare config: any;
|
||||||
declare useTransaction: boolean;
|
declare useTransaction: boolean;
|
||||||
declare executed: boolean;
|
declare executed: number;
|
||||||
|
|
||||||
declare createdAt: Date;
|
declare createdAt: Date;
|
||||||
declare updatedAt: Date;
|
declare updatedAt: Date;
|
||||||
@ -68,15 +68,15 @@ export default class WorkflowModel extends Model {
|
|||||||
transaction: transaction.id
|
transaction: transaction.id
|
||||||
}, { transaction });
|
}, { transaction });
|
||||||
|
|
||||||
|
const executed = await this.countExecutions({ transaction });
|
||||||
|
|
||||||
|
// NOTE: not to trigger afterUpdate hook here
|
||||||
|
await this.update({ executed }, { transaction, hooks: false });
|
||||||
|
|
||||||
execution.workflow = this;
|
execution.workflow = this;
|
||||||
|
|
||||||
await execution.start({ transaction });
|
await execution.start({ transaction });
|
||||||
|
|
||||||
if (!this.executed) {
|
|
||||||
// NOTE: not to trigger afterUpdate hook here
|
|
||||||
await this.update({ executed: true }, { transaction, hooks: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (transaction && (!options.transaction || options.transaction.finished)) {
|
if (transaction && (!options.transaction || options.transaction.finished)) {
|
||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
|
Loading…
Reference in New Issue
Block a user