mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 02:32:19 +08:00
feat(plugin-workflow): add checker for intervally dispatching (#4119)
This commit is contained in:
parent
e25d15518e
commit
5bcaa9d11f
@ -45,6 +45,7 @@ export default class PluginWorkflowServer extends Plugin {
|
||||
|
||||
private loggerCache: LRUCache<string, Logger>;
|
||||
private meter = null;
|
||||
private checker: NodeJS.Timeout = null;
|
||||
|
||||
private onBeforeSave = async (instance: WorkflowModel, options) => {
|
||||
const Model = <typeof WorkflowModel>instance.constructor;
|
||||
@ -245,6 +246,10 @@ export default class PluginWorkflowServer extends Plugin {
|
||||
workflows.forEach((workflow: WorkflowModel) => {
|
||||
this.toggle(workflow);
|
||||
});
|
||||
|
||||
this.checker = setInterval(() => {
|
||||
this.dispatch();
|
||||
}, 300_000);
|
||||
});
|
||||
|
||||
this.app.on('afterStart', () => {
|
||||
@ -271,6 +276,10 @@ export default class PluginWorkflowServer extends Plugin {
|
||||
if (this.executing) {
|
||||
await this.executing;
|
||||
}
|
||||
|
||||
if (this.checker) {
|
||||
clearInterval(this.checker);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -466,6 +475,7 @@ export default class PluginWorkflowServer extends Plugin {
|
||||
|
||||
this.executing = (async () => {
|
||||
let next: Pending | null = null;
|
||||
try {
|
||||
// resuming has high priority
|
||||
if (this.pending.length) {
|
||||
next = this.pending.shift() as Pending;
|
||||
@ -480,7 +490,7 @@ export default class PluginWorkflowServer extends Plugin {
|
||||
},
|
||||
},
|
||||
appends: ['workflow'],
|
||||
sort: 'createdAt',
|
||||
sort: 'id',
|
||||
})) as ExecutionModel;
|
||||
if (execution) {
|
||||
this.getLogger(execution.workflowId).info(`execution (${execution.id}) fetched from db`);
|
||||
@ -490,12 +500,13 @@ export default class PluginWorkflowServer extends Plugin {
|
||||
if (next) {
|
||||
await this.process(...next);
|
||||
}
|
||||
|
||||
} finally {
|
||||
this.executing = null;
|
||||
|
||||
if (next) {
|
||||
this.dispatch();
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user