Skip to content

Commit

Permalink
feat: 实现触发器配置变更时,更新调度器任务;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jul 29, 2021
1 parent 3ea4713 commit 1d8dbe5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/app-server/src/lib/scheduler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ accessor.ready.then(async () => {
stream.on("change", (doc) => {
DatabaseChangeEventCallBack(doc)
})

})

// 对应用访问策略的函数进行防抖动处理
Expand All @@ -59,6 +58,27 @@ function DatabaseChangeEventCallBack(doc: ChangeStreamDocument) {
debouncedApplyPolicy()
}

// 触发器配置变更时,更新调度器
if (collection === Constants.trigger_collection) {
if (['insert', 'update', 'replace'].includes(operationType)) {
const trigger = Trigger.fromJson(doc.fullDocument)
Scheduler.updateTrigger(trigger)
}

if (operationType === 'delete') {
getTriggers()
.then(data => {
const triggers = data.map(it => Trigger.fromJson(it))
Scheduler.init(triggers)
})
.catch(err => logger.error(err))
}
}

if(collection.startsWith('__')) {
return
}

// 触发数据变更事件
const event = `DatabaseChange:${collection}#${operationType}`
Scheduler.emit(event, doc)
Expand Down Expand Up @@ -96,6 +116,10 @@ export function AccessorEventCallBack(data: any) {
return
}

if(params.collection?.startsWith('__')) {
return
}

// 触发数据事件
const event = `/db/${params.collection}#${op}`
Scheduler.emit(event, {
Expand Down

0 comments on commit 1d8dbe5

Please sign in to comment.