mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-02 20:27:49 +08:00
test(plugin-workflow): add cache and test for sqlite (#1194)
This commit is contained in:
parent
c19ca1f30b
commit
6fb58d01a3
@ -22,7 +22,7 @@ export default class WorkflowPlugin extends Plugin {
|
||||
triggers: Registry<Trigger> = new Registry();
|
||||
calculators = calculators;
|
||||
extensions = extensions;
|
||||
executing: ExecutionModel = null;
|
||||
executing: ExecutionModel | null = null;
|
||||
pending: Pending[] = [];
|
||||
events: [WorkflowModel, any, { context?: any }][] = [];
|
||||
|
||||
@ -133,7 +133,7 @@ export default class WorkflowPlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
public trigger(workflow: WorkflowModel, context: Object, options: { context?: any } = {}): Promise<void> {
|
||||
public trigger(workflow: WorkflowModel, context: Object, options: { context?: any } = {}): void {
|
||||
// `null` means not to trigger
|
||||
if (context == null) {
|
||||
return;
|
||||
@ -166,7 +166,7 @@ export default class WorkflowPlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
await this.db.sequelize.transaction(async transaction => {
|
||||
const execution = await this.db.sequelize.transaction(async transaction => {
|
||||
const execution = await workflow.createExecution({
|
||||
context,
|
||||
key: workflow.key,
|
||||
@ -200,6 +200,11 @@ export default class WorkflowPlugin extends Plugin {
|
||||
return execution;
|
||||
});
|
||||
|
||||
// NOTE: cache first execution for most cases
|
||||
if (!this.executing && !this.pending.length) {
|
||||
this.pending.push([execution]);
|
||||
}
|
||||
|
||||
this.events.shift();
|
||||
|
||||
if (this.events.length) {
|
||||
@ -223,10 +228,10 @@ export default class WorkflowPlugin extends Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
let next: Pending;
|
||||
let next: Pending | null = null;
|
||||
// resuming has high priority
|
||||
if (this.pending.length) {
|
||||
next = this.pending.shift();
|
||||
next = this.pending.shift() as Pending;
|
||||
} else {
|
||||
const execution = await this.db.getRepository('executions').findOne({
|
||||
filter: {
|
||||
|
@ -219,7 +219,7 @@ describe('workflow > Plugin', () => {
|
||||
});
|
||||
|
||||
describe('dispatcher', () => {
|
||||
it.skip('multiple triggers in same event', async () => {
|
||||
it('multiple triggers in same event', async () => {
|
||||
const w1 = await WorkflowModel.create({
|
||||
enabled: true,
|
||||
type: 'collection',
|
||||
|
Loading…
Reference in New Issue
Block a user