👕 Fix lint issues

This commit is contained in:
Jan Oberhauser
2019-11-02 12:16:20 +01:00
parent ab3e10db04
commit ab6cc43a4c
3 changed files with 36 additions and 58 deletions

View File

@@ -1,9 +1,10 @@
import { ContainerOptions } from 'rhea';
import { ITriggerFunctions } from 'n8n-core';
import {
INodeType,
INodeTypeDescription,
ITriggerResponse,
} from 'n8n-workflow';
@@ -67,40 +68,40 @@ export class AmqpTrigger implements INodeType {
const clientname = this.getNodeParameter('clientname', '') as string;
const subscription = this.getNodeParameter('subscription', '') as string;
if (sink == '') {
if (sink === '') {
throw new Error('Queue or Topic required!');
}
let durable: boolean = false;
let durable = false;
if(subscription && clientname) {
durable = true;
}
let container = require('rhea');
let connectOptions = {
const container = require('rhea');
const connectOptions: ContainerOptions = {
host: credentials.hostname,
port: credentials.port,
reconnect: true, // this id the default anyway
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
container_id: (durable ? clientname : null)
}
};
if (credentials.username || credentials.password) {
container.options.username = credentials.username;
container.options.password = credentials.password;
}
let lastMsgId: any = undefined;
let self = this;
let lastMsgId: number | undefined = undefined;
const self = this;
container.on('message', function (context: any) {
if (context.message.message_id && context.message.message_id == lastMsgId) {
container.on('message', (context: any) => { // tslint:disable-line:no-any
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
lastMsgId = context.message.message_id;
return;
}
self.emit([self.helpers.returnJsonArray([context.message])]);
});
let connection = container.connect(connectOptions);
const connection = container.connect(connectOptions);
let clientOptions = undefined;
if (durable) {
clientOptions = {
@@ -111,14 +112,14 @@ export class AmqpTrigger implements INodeType {
expiry_policy: 'never'
},
credit_window: 1 // prefetch 1
}
};
} else {
clientOptions = {
source: {
address: sink,
},
credit_window: 1 // prefetch 1
}
};
}
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 a new user who doesn't know how this works, it's better to wait and show a respective info message
async function manualTriggerFunction() {
await new Promise( function( resolve ) {
let timeoutHandler = setTimeout(function() {
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);
await new Promise(( resolve, reject ) => {
const timeoutHandler = setTimeout(() => {
reject(new Error('Aborted, no message received within 30secs. This 30sec timeout is only set for "manually triggered execution". Active Workflows will listen indefinitely.'));
}, 30000);
container.on('message', function (context: any) {
container.on('message', (context: any) => { // tslint:disable-line:no-any
clearTimeout(timeoutHandler);
resolve(true);
});