🐛 Fix bug that workflows did not get activated correctly

This commit is contained in:
Jan Oberhauser
2020-08-30 11:06:46 +02:00
parent 10cfe70d33
commit 22c40d026b
5 changed files with 19 additions and 172 deletions

View File

@@ -52,6 +52,9 @@ export class ActiveWorkflowRunner {
// so intead of pulling all the active wehhooks just pull the actives that have a trigger
const workflowsData: IWorkflowDb[] = await Db.collections.Workflow!.find({ active: true }) as IWorkflowDb[];
// Clear up active workflow table
await Db.collections.Webhook?.clear();
this.activeWorkflows = new ActiveWorkflows();
if (workflowsData.length !== 0) {
@@ -59,22 +62,14 @@ export class ActiveWorkflowRunner {
console.log(' Start Active Workflows:');
console.log(' ================================');
const nodeTypes = NodeTypes();
for (const workflowData of workflowsData) {
const workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings});
if (workflow.getTriggerNodes().length !== 0
|| workflow.getPollNodes().length !== 0) {
console.log(` - ${workflowData.name}`);
try {
await this.add(workflowData.id.toString(), workflowData);
console.log(` => Started`);
} catch (error) {
console.log(` => ERROR: Workflow could not be activated:`);
console.log(` ${error.message}`);
}
console.log(` - ${workflowData.name}`);
try {
await this.add(workflowData.id.toString(), workflowData);
console.log(` => Started`);
} catch (error) {
console.log(` => ERROR: Workflow could not be activated:`);
console.log(` ${error.message}`);
}
}
}
@@ -87,14 +82,18 @@ export class ActiveWorkflowRunner {
* @memberof ActiveWorkflowRunner
*/
async removeAll(): Promise<void> {
if (this.activeWorkflows === null) {
return;
const activeWorkflowId: string[] = [];
if (this.activeWorkflows !== null) {
// TODO: This should be renamed!
activeWorkflowId.push.apply(activeWorkflowId, this.activeWorkflows.allActiveWorkflows());
}
const activeWorkflows = this.activeWorkflows.allActiveWorkflows();
const activeWorkflows = await this.getActiveWorkflows();
activeWorkflowId.push.apply(activeWorkflowId, activeWorkflows.map(workflow => workflow.id));
const removePromises = [];
for (const workflowId of activeWorkflows) {
for (const workflowId of activeWorkflowId) {
removePromises.push(this.remove(workflowId));
}
@@ -183,7 +182,7 @@ export class ActiveWorkflowRunner {
* @memberof ActiveWorkflowRunner
*/
getActiveWorkflows(): Promise<IWorkflowDb[]> {
return Db.collections.Workflow?.find({ select: ['id'] }) as Promise<IWorkflowDb[]>;
return Db.collections.Workflow?.find({ where: { active: true }, select: ['id'] }) as Promise<IWorkflowDb[]>;
}