From 16498dcbde908a608ebe8d564e24404264f18499 Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 6 May 2022 13:55:36 +0800 Subject: [PATCH] Fix(plugin workflow): fix transaction of execution (#364) * fix(plugin-workflow): fix values dropdown height * fix(plugin-workflow): fix duplicated property name --- .../core/client/src/workflow/calculators.tsx | 5 ++++- .../workflow/src/collections/workflows.ts | 15 +++++++++++++++ .../plugins/workflow/src/instructions/create.ts | 2 +- .../plugins/workflow/src/instructions/destroy.ts | 2 +- .../workflow/src/instructions/parallel.ts | 2 +- .../plugins/workflow/src/instructions/query.ts | 2 +- .../plugins/workflow/src/instructions/update.ts | 2 +- .../plugins/workflow/src/models/Execution.ts | 16 +++++++++------- 8 files changed, 33 insertions(+), 13 deletions(-) diff --git a/packages/core/client/src/workflow/calculators.tsx b/packages/core/client/src/workflow/calculators.tsx index 94047509d..e30bcbb9f 100644 --- a/packages/core/client/src/workflow/calculators.tsx +++ b/packages/core/client/src/workflow/calculators.tsx @@ -456,7 +456,10 @@ export const CollectionFieldset = observer(({ value, onChange }: any) => { {Object.keys(value).length < fields.length ? ( onChange({ ...value, [key]: null })}> + onChange({ ...value, [key]: null })} className={css` + max-height: 300px; + overflow-y: auto; + `}> {fields .filter(field => !(field.name in value)) .map(field => ( diff --git a/packages/plugins/workflow/src/collections/workflows.ts b/packages/plugins/workflow/src/collections/workflows.ts index 16ec7a834..ca89e997a 100644 --- a/packages/plugins/workflow/src/collections/workflows.ts +++ b/packages/plugins/workflow/src/collections/workflows.ts @@ -60,6 +60,21 @@ export default { name: 'executions', target: 'executions', title: '触发执行' + }, + { + type: 'boolean', + name: 'executed', + defaultValue: false + }, + { + type: 'hasMany', + name: 'revisions', + target: 'workflows', + }, + { + type: 'belongsTo', + name: 'current', + target: 'workflows' } ] } as CollectionOptions; diff --git a/packages/plugins/workflow/src/instructions/create.ts b/packages/plugins/workflow/src/instructions/create.ts index 8119450aa..8757ba774 100644 --- a/packages/plugins/workflow/src/instructions/create.ts +++ b/packages/plugins/workflow/src/instructions/create.ts @@ -12,7 +12,7 @@ export default { const options = execution.getParsedValue(params); const result = await repo.create({ ...options, - transaction: execution.transaction + transaction: execution.tx }); return { diff --git a/packages/plugins/workflow/src/instructions/destroy.ts b/packages/plugins/workflow/src/instructions/destroy.ts index 7b52808b4..040b6fd69 100644 --- a/packages/plugins/workflow/src/instructions/destroy.ts +++ b/packages/plugins/workflow/src/instructions/destroy.ts @@ -12,7 +12,7 @@ export default { const options = execution.getParsedValue(params); const result = await repo.destroy({ ...options, - transaction: execution.transaction + transaction: execution.tx }); return { diff --git a/packages/plugins/workflow/src/instructions/parallel.ts b/packages/plugins/workflow/src/instructions/parallel.ts index 31b0795b5..c81ab6b54 100644 --- a/packages/plugins/workflow/src/instructions/parallel.ts +++ b/packages/plugins/workflow/src/instructions/parallel.ts @@ -83,7 +83,7 @@ export default { }); if (job.status === JOB_STATUS.PENDING) { - await job.save({ transaction: execution.transaction }); + await job.save({ transaction: execution.tx }); return execution.end(this, job); } diff --git a/packages/plugins/workflow/src/instructions/query.ts b/packages/plugins/workflow/src/instructions/query.ts index 6a5cdff8f..717422a64 100644 --- a/packages/plugins/workflow/src/instructions/query.ts +++ b/packages/plugins/workflow/src/instructions/query.ts @@ -13,7 +13,7 @@ export default { const options = execution.getParsedValue(params); const result = await (multiple ? repo.find : repo.findOne).call(repo, { ...options, - transaction: execution.transaction + transaction: execution.tx }); return { diff --git a/packages/plugins/workflow/src/instructions/update.ts b/packages/plugins/workflow/src/instructions/update.ts index 66abbeb1b..ccc6438c8 100644 --- a/packages/plugins/workflow/src/instructions/update.ts +++ b/packages/plugins/workflow/src/instructions/update.ts @@ -13,7 +13,7 @@ export default { const options = execution.getParsedValue(params); const result = await repo.update({ ...options, - transaction: execution.transaction + transaction: execution.tx }); return { diff --git a/packages/plugins/workflow/src/models/Execution.ts b/packages/plugins/workflow/src/models/Execution.ts index 9d0e15435..f28cbae35 100644 --- a/packages/plugins/workflow/src/models/Execution.ts +++ b/packages/plugins/workflow/src/models/Execution.ts @@ -21,6 +21,7 @@ export default class ExecutionModel extends Model { declare status: number; // NOTE: this duplicated column is for transaction in preparing cycle from workflow declare useTransaction: boolean; + declare transaction: string; declare createdAt: Date; declare updatedAt: Date; @@ -32,7 +33,8 @@ export default class ExecutionModel extends Model { declare getJobs: HasManyGetAssociationsMixin; options: ExecutionOptions; - transaction: Transaction; + + tx: Transaction; nodes: Array = []; nodesMap = new Map(); @@ -98,7 +100,7 @@ export default class ExecutionModel extends Model { async prepare(options, commit = false) { this.options = options || {}; const transaction = await this.getTransaction(); - this.transaction = transaction; + this.tx = transaction; if (!this.workflow) { this.workflow = await this.getWorkflow({ transaction }); @@ -146,8 +148,8 @@ export default class ExecutionModel extends Model { private async commit() { // @ts-ignore - if (this.transaction && (!this.options.transaction || this.options.transaction.finished)) { - await this.transaction.commit(); + if (this.tx && (!this.options.transaction || this.options.transaction.finished)) { + await this.tx.commit(); } } @@ -178,7 +180,7 @@ export default class ExecutionModel extends Model { // TODO(optimize): many checking of resuming or new could be improved // could be implemented separately in exec() / resume() if (job instanceof Model) { - savedJob = (await job.save({ transaction: this.transaction })) as unknown as JobModel; + savedJob = (await job.save({ transaction: this.tx })) as unknown as JobModel; } else { const upstreamId = prevJob instanceof Model ? prevJob.get('id') : null; savedJob = await this.saveJob({ @@ -230,7 +232,7 @@ export default class ExecutionModel extends Model { async exit(job: JobModel | null) { const status = job ? ExecutionModel.StatusMap[job.status] : EXECUTION_STATUS.RESOLVED; - await this.update({ status }, { transaction: this.transaction }); + await this.update({ status }, { transaction: this.tx }); return null; } @@ -243,7 +245,7 @@ export default class ExecutionModel extends Model { ...payload, executionId: this.id, }, - { transaction: this.transaction }, + { transaction: this.tx }, )) as unknown as [JobModel, boolean | null]; this.jobsMap.set(job.id, job); this.jobsMapByNodeId[job.nodeId] = job.result;