Improvements

This commit is contained in:
ricardo 2020-05-30 19:03:58 -04:00
parent 91c40367e1
commit 4e9490a88d
11 changed files with 62 additions and 45 deletions

View file

@ -241,13 +241,26 @@ export class ActiveWorkflowRunner {
}
} catch (error) {
// The workflow was saved with two webhooks with the
// same path/method so delete all webhooks saved
let errorMessage = '';
await Db.collections.Webhook?.delete({ workflowId: workflow.id });
// then show error to the user
throw new Error(error.message || error.detail);
// if it's a workflow from the the insert
// TODO check if there is standard error code for deplicate key violation that works
// with all databases
if (error.name === 'QueryFailedError') {
errorMessage = `The webhook path [${webhook.webhookPath}] and method [${webhook.method}] already exist.`;
} else if (error.detail) {
// it's a error runnig the webhook methods (checkExists, create)
errorMessage = error.detail;
} else {
errorMessage = error;
}
throw new Error(errorMessage);
}
}
// Save static data!

View file

@ -44,7 +44,6 @@ export interface IDatabaseCollections {
}
export interface IWebhookDb {
id?: number | ObjectID;
workflowId: number | string | ObjectID;
webhookPath: string;
method: string;

View file

@ -141,12 +141,14 @@ export class TestWebhooks {
let key: string;
for (const webhookData of webhooks) {
key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
await this.activeWebhooks!.add(workflow, webhookData, mode);
this.testWebhookData[key] = {
sessionId,
timeout,
workflowData,
};
await this.activeWebhooks!.add(workflow, webhookData, mode);
// Save static data!
this.testWebhookData[key].workflowData.staticData = workflow.staticData;

View file

@ -1,9 +1,7 @@
import {
Column,
Entity,
Unique,
ObjectIdColumn,
ObjectID,
PrimaryColumn,
} from 'typeorm';
import {
@ -11,19 +9,15 @@ import {
} from '../../Interfaces';
@Entity()
@Unique(['webhookPath', 'method'])
export class WebhookEntity implements IWebhookDb {
@ObjectIdColumn()
id: ObjectID;
@Column()
workflowId: number;
@Column()
@PrimaryColumn()
webhookPath: string;
@Column()
@PrimaryColumn()
method: string;
@Column()

View file

@ -1,8 +1,7 @@
import {
Column,
Entity,
Unique,
PrimaryGeneratedColumn,
PrimaryColumn,
} from 'typeorm';
import {
@ -10,19 +9,15 @@ import {
} from '../../Interfaces';
@Entity()
@Unique(['webhookPath', 'method'])
export class WebhookEntity implements IWebhookDb {
@PrimaryGeneratedColumn()
id: number;
@Column()
workflowId: number;
@Column()
@PrimaryColumn()
webhookPath: string;
@Column()
@PrimaryColumn()
method: string;
@Column()

View file

@ -1,8 +1,7 @@
import {
Column,
Entity,
Unique,
PrimaryGeneratedColumn,
PrimaryColumn,
} from 'typeorm';
import {
@ -10,19 +9,15 @@ import {
} from '../../';
@Entity()
@Unique(['webhookPath', 'method'])
export class WebhookEntity implements IWebhookDb {
@PrimaryGeneratedColumn()
id: number;
@Column()
workflowId: number;
@Column()
@PrimaryColumn()
webhookPath: string;
@Column()
@PrimaryColumn()
method: string;
@Column()

View file

@ -1,4 +1,5 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import {
MigrationInterface, QueryRunner } from 'typeorm';
import * as config from '../../../../config';

View file

@ -1,7 +1,18 @@
import {MigrationInterface, QueryRunner} from 'typeorm';
import {
MigrationInterface,
QueryRunner,
} from 'typeorm';
import {
IWorkflowDb,
NodeTypes,
WebhookHelpers,
} from '../../..';
import {
Workflow,
} from 'n8n-workflow/dist/src/Workflow';
import { IWorkflowDb, NodeTypes, WebhookHelpers } from '../../..';
import { Workflow } from 'n8n-workflow/dist/src/Workflow';
import {
IWebhookDb,
} from '../../../Interfaces';
@ -18,7 +29,7 @@ export class WebhookModel1589476000887 implements MigrationInterface {
tablePrefix = schema + '.' + tablePrefix;
}
await queryRunner.query(`CREATE TABLE ${tablePrefix}webhook_entity ("id" SERIAL NOT NULL, "workflowId" integer NOT NULL, "webhookPath" character varying NOT NULL, "method" character varying NOT NULL, "node" character varying NOT NULL, CONSTRAINT "UQ_b21ace2e13596ccd87dc9bf4ea6" UNIQUE ("webhookPath", "method"), CONSTRAINT "PK_202217c8b912cf70b93b1e87256" PRIMARY KEY ("id"))`, undefined);
await queryRunner.query(`CREATE TABLE ${tablePrefix}webhook_entity ("workflowId" integer NOT NULL, "webhookPath" character varying NOT NULL, "method" character varying NOT NULL, "node" character varying NOT NULL, CONSTRAINT "PK_b21ace2e13596ccd87dc9bf4ea6" PRIMARY KEY ("webhookPath", "method"))`, undefined);
const workflows = await queryRunner.query(`SELECT * FROM ${tablePrefix}workflow_entity WHERE active=true`) as IWorkflowDb[];
const data: IWebhookDb[] = [];

View file

@ -1,8 +1,7 @@
import {
Column,
Entity,
Unique,
PrimaryGeneratedColumn,
PrimaryColumn,
} from 'typeorm';
import {
@ -10,19 +9,15 @@ import {
} from '../../Interfaces';
@Entity()
@Unique(['webhookPath', 'method'])
export class WebhookEntity implements IWebhookDb {
@PrimaryGeneratedColumn()
id: number;
@Column()
workflowId: number;
@Column()
@PrimaryColumn()
webhookPath: string;
@Column()
@PrimaryColumn()
method: string;
@Column()

View file

@ -35,13 +35,20 @@ export class ActiveWebhooks {
throw new Error('Webhooks can only be added for saved workflows as an id is needed!');
}
const webhookKey = this.getWebhookKey(webhookData.httpMethod, webhookData.path);
//check that there is not a webhook already registed with that path/method
if (this.webhookUrls[webhookKey] !== undefined) {
throw new Error('There is test wenhook registered on that path');
}
if (this.workflowWebhooks[webhookData.workflowId] === undefined) {
this.workflowWebhooks[webhookData.workflowId] = [];
}
// Make the webhook available directly because sometimes to create it successfully
// it gets called
this.webhookUrls[this.getWebhookKey(webhookData.httpMethod, webhookData.path)] = webhookData;
this.webhookUrls[webhookKey] = webhookData;
const webhookExists = await workflow.runWebhookMethod('checkExists', webhookData, NodeExecuteFunctions, mode, this.testWebhooks);
if (webhookExists === false) {

View file

@ -1585,6 +1585,11 @@ export default mixins(
console.error(e); // eslint-disable-line no-console
}
node.parameters = nodeParameters !== null ? nodeParameters : {};
// if it's a webhook and the path is empty set the UUID as the default path
if (node.type === 'n8n-nodes-base.webhook' && node.parameters.path === '') {
node.parameters.path = node.webhookPath as string;
}
}
foundNodeIssues = this.getNodeIssues(nodeType, node);