fix(plugin-workflow): queueing execution of disabled workflow block dispatching (#3256)

* fix(plugin-workflow): queueing execution of disabled workflow block dispatching

* fix(plugin-workflow): fix typo
This commit is contained in:
Junyi 2023-12-25 17:44:07 +08:00 committed by GitHub
parent cc2b132aa1
commit f17e10caa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 12 deletions

View File

@ -398,6 +398,7 @@ export default class WorkflowPlugin extends Plugin {
const execution = (await this.db.getRepository('executions').findOne({ const execution = (await this.db.getRepository('executions').findOne({
filter: { filter: {
status: EXECUTION_STATUS.QUEUEING, status: EXECUTION_STATUS.QUEUEING,
'workflow.enabled': true,
'workflow.id': { 'workflow.id': {
[Op.not]: null, [Op.not]: null,
}, },
@ -405,7 +406,7 @@ export default class WorkflowPlugin extends Plugin {
appends: ['workflow'], appends: ['workflow'],
sort: 'createdAt', sort: 'createdAt',
})) as ExecutionModel; })) as ExecutionModel;
if (execution && execution.workflow.enabled) { if (execution) {
this.getLogger(execution.workflowId).info(`execution (${execution.id}) fetched from db`); this.getLogger(execution.workflowId).info(`execution (${execution.id}) fetched from db`);
next = [execution]; next = [execution];
} }

View File

@ -356,10 +356,8 @@ describe('workflow > Plugin', () => {
const p1 = await PostRepo.create({ values: { title: 't1' } }); const p1 = await PostRepo.create({ values: { title: 't1' } });
const ExecutionModel = db.getCollection('executions').model; const ExecutionModel = db.getCollection('executions').model;
const e1 = await ExecutionModel.create({ const e1 = await w1.createExecution({
workflowId: w1.id,
key: w1.key, key: w1.key,
useTransaction: w1.useTransaction,
context: { context: {
data: p1.get(), data: p1.get(),
}, },
@ -378,10 +376,25 @@ describe('workflow > Plugin', () => {
await db.reconnect(); await db.reconnect();
const e2 = await ExecutionModel.create({ const e2 = await w1.createExecution({
workflowId: w1.id,
key: w1.key, key: w1.key,
useTransaction: w1.useTransaction, context: {
data: p1.get(),
},
createdAt: p1.createdAt,
});
const w2 = await WorkflowModel.create({
enabled: true,
type: 'collection',
config: {
mode: 1,
collection: 'posts',
},
});
const e3 = await w2.createExecution({
key: w2.key,
context: { context: {
data: p1.get(), data: p1.get(),
}, },
@ -393,6 +406,10 @@ describe('workflow > Plugin', () => {
await e2.reload(); await e2.reload();
expect(e2.status).toBe(EXECUTION_STATUS.QUEUEING); expect(e2.status).toBe(EXECUTION_STATUS.QUEUEING);
// queueing execution of disabled workflow should not effect other executions
await e3.reload();
expect(e3.status).toBe(EXECUTION_STATUS.RESOLVED);
}); });
}); });

View File

@ -13,11 +13,6 @@ export default {
type: 'uid', type: 'uid',
name: 'key', name: 'key',
}, },
{
type: 'boolean',
name: 'useTransaction',
defaultValue: false,
},
{ {
type: 'hasMany', type: 'hasMany',
name: 'jobs', name: 'jobs',