mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:57:53 +00:00
Merge branch 'main' into next
This commit is contained in:
commit
ea1a6210db
@ -403,4 +403,42 @@ describe('workflow > triggers > schedule > date field mode', () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -357,7 +357,6 @@ export default class ScheduleTrigger {
|
||||
const { collection } = workflow.config;
|
||||
const [dataSourceName, collectionName] = parseCollectionName(collection);
|
||||
const event = `${collectionName}.afterSaveWithAssociations`;
|
||||
const eventKey = `${collection}.afterSaveWithAssociations`;
|
||||
const name = getHookId(workflow, event);
|
||||
if (this.events.has(name)) {
|
||||
return;
|
||||
@ -384,14 +383,13 @@ export default class ScheduleTrigger {
|
||||
const { collection } = workflow.config;
|
||||
const [dataSourceName, collectionName] = parseCollectionName(collection);
|
||||
const event = `${collectionName}.afterSaveWithAssociations`;
|
||||
const eventKey = `${collection}.afterSaveWithAssociations`;
|
||||
const name = getHookId(workflow, event);
|
||||
if (this.events.has(eventKey)) {
|
||||
const listener = this.events.get(name);
|
||||
if (listener) {
|
||||
// @ts-ignore
|
||||
const { db } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager;
|
||||
db.off(event, listener);
|
||||
this.events.delete(eventKey);
|
||||
this.events.delete(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user