mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
👕 Fix lint issues
This commit is contained in:
parent
ab3e10db04
commit
ab6cc43a4c
|
@ -8,9 +8,6 @@ export class Amqp implements ICredentialType {
|
||||||
name = 'amqp';
|
name = 'amqp';
|
||||||
displayName = 'AMQP';
|
displayName = 'AMQP';
|
||||||
properties = [
|
properties = [
|
||||||
// The credentials to get from user and save encrypted.
|
|
||||||
// Properties can be defined exactly in the same way
|
|
||||||
// as node properties.
|
|
||||||
{
|
{
|
||||||
displayName: 'Hostname',
|
displayName: 'Hostname',
|
||||||
name: 'hostname',
|
name: 'hostname',
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
import { ContainerOptions, Delivery } from 'rhea';
|
||||||
|
|
||||||
import { IExecuteSingleFunctions } from 'n8n-core';
|
import { IExecuteSingleFunctions } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { Delivery } from 'rhea';
|
|
||||||
|
|
||||||
export class Amqp implements INodeType {
|
export class Amqp implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -26,23 +26,6 @@ export class Amqp implements INodeType {
|
||||||
required: true,
|
required: true,
|
||||||
}],
|
}],
|
||||||
properties: [
|
properties: [
|
||||||
{
|
|
||||||
displayName: 'Host',
|
|
||||||
name: 'hostname',
|
|
||||||
type: 'string',
|
|
||||||
default: 'localhost',
|
|
||||||
description: 'hostname of the amqp server',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Port',
|
|
||||||
name: 'port',
|
|
||||||
type: 'number',
|
|
||||||
typeOptions: {
|
|
||||||
minValue: 1,
|
|
||||||
},
|
|
||||||
default: 5672,
|
|
||||||
description: 'TCP Port to connect to',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Queue / Topic',
|
displayName: 'Queue / Topic',
|
||||||
name: 'sink',
|
name: 'sink',
|
||||||
|
@ -71,38 +54,39 @@ export class Amqp implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
const sink = this.getNodeParameter('sink', '') as string;
|
const sink = this.getNodeParameter('sink', '') as string;
|
||||||
let applicationProperties = this.getNodeParameter('headerParametersJson', {}) as string | object;
|
const applicationProperties = this.getNodeParameter('headerParametersJson', {}) as string | object;
|
||||||
|
|
||||||
let headerProperties = applicationProperties;
|
let headerProperties = applicationProperties;
|
||||||
if(typeof applicationProperties === 'string' && applicationProperties != '') {
|
if(typeof applicationProperties === 'string' && applicationProperties !== '') {
|
||||||
headerProperties = JSON.parse(applicationProperties)
|
headerProperties = JSON.parse(applicationProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sink == '') {
|
if (sink === '') {
|
||||||
throw new Error('Queue or Topic required!');
|
throw new Error('Queue or Topic required!');
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = require('rhea');
|
const container = require('rhea');
|
||||||
|
|
||||||
let connectOptions = {
|
const connectOptions: ContainerOptions = {
|
||||||
host: credentials.hostname,
|
host: credentials.hostname,
|
||||||
port: credentials.port,
|
port: credentials.port,
|
||||||
reconnect: true, // this id the default anyway
|
reconnect: true, // this id the default anyway
|
||||||
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
|
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
|
||||||
}
|
};
|
||||||
if (credentials.username || credentials.password) {
|
if (credentials.username || credentials.password) {
|
||||||
container.options.username = credentials.username;
|
container.options.username = credentials.username;
|
||||||
container.options.password = credentials.password;
|
container.options.password = credentials.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
let allSent = new Promise( function( resolve ) {
|
const allSent = new Promise(( resolve ) => {
|
||||||
container.on('sendable', function (context: any) {
|
container.on('sendable', (context: any) => { // tslint:disable-line:no-any
|
||||||
|
|
||||||
let message = {
|
const message = {
|
||||||
application_properties: headerProperties,
|
application_properties: headerProperties,
|
||||||
body: JSON.stringify(item)
|
body: JSON.stringify(item)
|
||||||
}
|
};
|
||||||
let sendResult = context.sender.send(message);
|
|
||||||
|
const sendResult = context.sender.send(message);
|
||||||
|
|
||||||
resolve(sendResult);
|
resolve(sendResult);
|
||||||
});
|
});
|
||||||
|
@ -110,7 +94,7 @@ export class Amqp implements INodeType {
|
||||||
|
|
||||||
container.connect(connectOptions).open_sender(sink);
|
container.connect(connectOptions).open_sender(sink);
|
||||||
|
|
||||||
let sendResult: Delivery = await allSent as Delivery; // sendResult has a a property that causes circular reference if returned
|
const sendResult: Delivery = await allSent as Delivery; // sendResult has a a property that causes circular reference if returned
|
||||||
|
|
||||||
return { json: { id: sendResult.id } } as INodeExecutionData;
|
return { json: { id: sendResult.id } } as INodeExecutionData;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
import { ContainerOptions } from 'rhea';
|
||||||
|
|
||||||
import { ITriggerFunctions } from 'n8n-core';
|
import { ITriggerFunctions } from 'n8n-core';
|
||||||
import {
|
import {
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
ITriggerResponse,
|
ITriggerResponse,
|
||||||
|
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,32 +68,32 @@ export class AmqpTrigger implements INodeType {
|
||||||
const clientname = this.getNodeParameter('clientname', '') as string;
|
const clientname = this.getNodeParameter('clientname', '') as string;
|
||||||
const subscription = this.getNodeParameter('subscription', '') as string;
|
const subscription = this.getNodeParameter('subscription', '') as string;
|
||||||
|
|
||||||
if (sink == '') {
|
if (sink === '') {
|
||||||
throw new Error('Queue or Topic required!');
|
throw new Error('Queue or Topic required!');
|
||||||
}
|
}
|
||||||
let durable: boolean = false;
|
let durable = false;
|
||||||
if(subscription && clientname) {
|
if(subscription && clientname) {
|
||||||
durable = true;
|
durable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = require('rhea');
|
const container = require('rhea');
|
||||||
let connectOptions = {
|
const connectOptions: ContainerOptions = {
|
||||||
host: credentials.hostname,
|
host: credentials.hostname,
|
||||||
port: credentials.port,
|
port: credentials.port,
|
||||||
reconnect: true, // this id the default anyway
|
reconnect: true, // this id the default anyway
|
||||||
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
|
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
|
||||||
container_id: (durable ? clientname : null)
|
container_id: (durable ? clientname : null)
|
||||||
}
|
};
|
||||||
if (credentials.username || credentials.password) {
|
if (credentials.username || credentials.password) {
|
||||||
container.options.username = credentials.username;
|
container.options.username = credentials.username;
|
||||||
container.options.password = credentials.password;
|
container.options.password = credentials.password;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastMsgId: any = undefined;
|
let lastMsgId: number | undefined = undefined;
|
||||||
let self = this;
|
const self = this;
|
||||||
|
|
||||||
container.on('message', function (context: any) {
|
container.on('message', (context: any) => { // tslint:disable-line:no-any
|
||||||
if (context.message.message_id && context.message.message_id == lastMsgId) {
|
if (context.message.message_id && context.message.message_id === lastMsgId) {
|
||||||
// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
|
// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
|
||||||
lastMsgId = context.message.message_id;
|
lastMsgId = context.message.message_id;
|
||||||
return;
|
return;
|
||||||
|
@ -100,7 +101,7 @@ export class AmqpTrigger implements INodeType {
|
||||||
self.emit([self.helpers.returnJsonArray([context.message])]);
|
self.emit([self.helpers.returnJsonArray([context.message])]);
|
||||||
});
|
});
|
||||||
|
|
||||||
let connection = container.connect(connectOptions);
|
const connection = container.connect(connectOptions);
|
||||||
let clientOptions = undefined;
|
let clientOptions = undefined;
|
||||||
if (durable) {
|
if (durable) {
|
||||||
clientOptions = {
|
clientOptions = {
|
||||||
|
@ -111,14 +112,14 @@ export class AmqpTrigger implements INodeType {
|
||||||
expiry_policy: 'never'
|
expiry_policy: 'never'
|
||||||
},
|
},
|
||||||
credit_window: 1 // prefetch 1
|
credit_window: 1 // prefetch 1
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
clientOptions = {
|
clientOptions = {
|
||||||
source: {
|
source: {
|
||||||
address: sink,
|
address: sink,
|
||||||
},
|
},
|
||||||
credit_window: 1 // prefetch 1
|
credit_window: 1 // prefetch 1
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
connection.open_receiver(clientOptions);
|
connection.open_receiver(clientOptions);
|
||||||
|
|
||||||
|
@ -135,15 +136,11 @@ export class AmqpTrigger implements INodeType {
|
||||||
// for AMQP it doesn't make much sense to wait here but
|
// for AMQP it doesn't make much sense to wait here but
|
||||||
// for a new user who doesn't know how this works, it's better to wait and show a respective info message
|
// for a new user who doesn't know how this works, it's better to wait and show a respective info message
|
||||||
async function manualTriggerFunction() {
|
async function manualTriggerFunction() {
|
||||||
|
await new Promise(( resolve, reject ) => {
|
||||||
await new Promise( function( resolve ) {
|
const timeoutHandler = setTimeout(() => {
|
||||||
let timeoutHandler = setTimeout(function() {
|
reject(new Error('Aborted, no message received within 30secs. This 30sec timeout is only set for "manually triggered execution". Active Workflows will listen indefinitely.'));
|
||||||
self.emit([self.helpers.returnJsonArray([{
|
|
||||||
error: 'Aborted, no message received within 30secs. This 30sec timeout is only set for "manually triggered execution". Active Workflows will listen indefinitely.'
|
|
||||||
}])]);
|
|
||||||
resolve(true);
|
|
||||||
}, 30000);
|
}, 30000);
|
||||||
container.on('message', function (context: any) {
|
container.on('message', (context: any) => { // tslint:disable-line:no-any
|
||||||
clearTimeout(timeoutHandler);
|
clearTimeout(timeoutHandler);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue