fix(plugin-workflow): fix missed preparing (#1337)
This commit is contained in:
parent
f6769341bd
commit
322194f24a
@ -2,4 +2,5 @@ import { AppLoggerOptions } from '@nocobase/logger';
|
||||
|
||||
export default {
|
||||
transports: process.env.LOGGER_TRANSPORT || ['console', 'dailyRotateFile'],
|
||||
level: process.env.LOGGER_LEVEL || (process.env.APP_ENV === 'development' ? 'debug' : 'info')
|
||||
} as AppLoggerOptions;
|
||||
|
@ -149,6 +149,8 @@ export default class WorkflowPlugin extends Plugin {
|
||||
|
||||
this.events.push([workflow, context, options]);
|
||||
|
||||
this.app.logger.debug(`[Workflow] new event triggered, now events: ${this.events.length}`);
|
||||
|
||||
if (this.events.length > 1) {
|
||||
return;
|
||||
}
|
||||
@ -164,6 +166,7 @@ export default class WorkflowPlugin extends Plugin {
|
||||
}
|
||||
const [workflow, context, options] = event;
|
||||
|
||||
let valid = true;
|
||||
if (options.context?.executionId) {
|
||||
// NOTE: no transaction here for read-uncommitted execution
|
||||
const existed = await workflow.countExecutions({
|
||||
@ -173,11 +176,12 @@ export default class WorkflowPlugin extends Plugin {
|
||||
});
|
||||
|
||||
if (existed) {
|
||||
console.warn(`workflow ${workflow.id} has already been triggered in same execution (${options.context.executionId}), and newly triggering will be skipped.`);
|
||||
return;
|
||||
this.app.logger.warn(`[Workflow] workflow ${workflow.id} has already been triggered in same execution (${options.context.executionId}), and newly triggering will be skipped.`);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
const execution = await this.db.sequelize.transaction(async transaction => {
|
||||
const execution = await workflow.createExecution({
|
||||
context,
|
||||
@ -212,10 +216,13 @@ export default class WorkflowPlugin extends Plugin {
|
||||
return execution;
|
||||
});
|
||||
|
||||
this.app.logger.debug(`[Workflow] execution of workflow ${workflow.id} created as ${execution.id}`);
|
||||
|
||||
// NOTE: cache first execution for most cases
|
||||
if (!this.executing && !this.pending.length) {
|
||||
this.pending.push([execution]);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.events.length) {
|
||||
await this.prepare();
|
||||
@ -267,9 +274,13 @@ export default class WorkflowPlugin extends Plugin {
|
||||
|
||||
const processor = this.createProcessor(execution);
|
||||
|
||||
console.log('workflow processing:', new Date(), execution.workflowId, execution.id);
|
||||
this.app.logger.info(`[Workflow] execution ${execution.id} ${job ? 'resuming' : 'starting'} ...`);
|
||||
|
||||
try {
|
||||
await (job ? processor.resume(job) : processor.start());
|
||||
} catch (err) {
|
||||
this.app.logger.error(`[Workflow] ${err.message}`, err);
|
||||
}
|
||||
|
||||
this.executing = null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user