Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-08-08 01:52:54 +00:00
commit ea1a6210db
2 changed files with 41 additions and 5 deletions

View File

@ -403,4 +403,42 @@ describe('workflow > triggers > schedule > date field mode', () => {
expect(e1c).toBe(2); expect(e1c).toBe(2);
}); });
}); });
describe('status', () => {
it('toggle off', async () => {
const workflow = await WorkflowModel.create({
enabled: true,
type: 'schedule',
config: {
mode: 1,
collection: 'posts',
startsOn: {
field: 'createdAt',
},
},
});
const now = await sleepToEvenSecond();
const p1 = await PostRepo.create({ values: { title: 't1' } });
await sleep(1500);
const executions = await workflow.getExecutions();
expect(executions.length).toBe(1);
expect(executions[0].context.data.id).toBe(p1.id);
const triggerTime = new Date(p1.createdAt);
triggerTime.setMilliseconds(0);
expect(executions[0].context.date).toBe(triggerTime.toISOString());
await workflow.update({ enabled: false });
const p2 = await PostRepo.create({ values: { title: 't2' } });
await sleep(1500);
const e2s = await workflow.getExecutions({ order: [['createdAt', 'ASC']] });
expect(e2s.length).toBe(1);
});
});
}); });

View File

@ -357,7 +357,6 @@ export default class ScheduleTrigger {
const { collection } = workflow.config; const { collection } = workflow.config;
const [dataSourceName, collectionName] = parseCollectionName(collection); const [dataSourceName, collectionName] = parseCollectionName(collection);
const event = `${collectionName}.afterSaveWithAssociations`; const event = `${collectionName}.afterSaveWithAssociations`;
const eventKey = `${collection}.afterSaveWithAssociations`;
const name = getHookId(workflow, event); const name = getHookId(workflow, event);
if (this.events.has(name)) { if (this.events.has(name)) {
return; return;
@ -384,14 +383,13 @@ export default class ScheduleTrigger {
const { collection } = workflow.config; const { collection } = workflow.config;
const [dataSourceName, collectionName] = parseCollectionName(collection); const [dataSourceName, collectionName] = parseCollectionName(collection);
const event = `${collectionName}.afterSaveWithAssociations`; const event = `${collectionName}.afterSaveWithAssociations`;
const eventKey = `${collection}.afterSaveWithAssociations`;
const name = getHookId(workflow, event); const name = getHookId(workflow, event);
if (this.events.has(eventKey)) {
const listener = this.events.get(name); const listener = this.events.get(name);
if (listener) {
// @ts-ignore // @ts-ignore
const { db } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager; const { db } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager;
db.off(event, listener); db.off(event, listener);
this.events.delete(eventKey); this.events.delete(name);
} }
} }
} }