test(plugin-workflow): add cache and test for sqlite (#1194)

This commit is contained in:
Junyi 2022-12-04 17:38:37 -08:00 committed by GitHub
parent c19ca1f30b
commit 6fb58d01a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -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: {

View File

@ -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',