mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Run requests in HTTP Request Node in parallel
This commit is contained in:
@@ -620,8 +620,8 @@ export class HttpRequest implements INodeType {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let response: any; // tslint:disable-line:no-any
|
|
||||||
const returnItems: INodeExecutionData[] = [];
|
const returnItems: INodeExecutionData[] = [];
|
||||||
|
const requestPromises = [];
|
||||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||||
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
|
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
|
||||||
const url = this.getNodeParameter('url', itemIndex) as string;
|
const url = this.getNodeParameter('url', itemIndex) as string;
|
||||||
@@ -814,27 +814,49 @@ export class HttpRequest implements INodeType {
|
|||||||
} else {
|
} else {
|
||||||
requestOptions.json = true;
|
requestOptions.json = true;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
// Now that the options are all set make the actual http request
|
// Now that the options are all set make the actual http request
|
||||||
if (oAuth1Api !== undefined) {
|
if (oAuth1Api !== undefined) {
|
||||||
//@ts-ignore
|
requestPromises.push(this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions));
|
||||||
response = await this.helpers.requestOAuth1.call(this, 'oAuth1Api', requestOptions);
|
} else if (oAuth2Api !== undefined) {
|
||||||
}
|
requestPromises.push(this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, { tokenType: 'Bearer' }));
|
||||||
else if (oAuth2Api !== undefined) {
|
} else {
|
||||||
//@ts-ignore
|
requestPromises.push(this.helpers.request(requestOptions));
|
||||||
response = await this.helpers.requestOAuth2.call(this, 'oAuth2Api', requestOptions, { tokenType: 'Bearer' });
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const promisesResponses = await Promise.allSettled(requestPromises);
|
||||||
|
|
||||||
|
let response: any; // tslint:disable-line:no-any
|
||||||
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||||
|
// @ts-ignore
|
||||||
|
response = promisesResponses.shift();
|
||||||
|
|
||||||
|
if (response!.status !== 'fulfilled') {
|
||||||
|
if (this.continueOnFail() !== true) {
|
||||||
|
// throw error;
|
||||||
|
throw new Error(response!.reason);
|
||||||
} else {
|
} else {
|
||||||
response = await this.helpers.request(requestOptions);
|
// Return the actual reason as error
|
||||||
}
|
returnItems.push(
|
||||||
} catch (error) {
|
{
|
||||||
if (this.continueOnFail() === true) {
|
json: {
|
||||||
returnItems.push({ json: { error } });
|
error: response.reason,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response = response.value;
|
||||||
|
|
||||||
|
const options = this.getNodeParameter('options', itemIndex, {}) as IDataObject;
|
||||||
|
const url = this.getNodeParameter('url', itemIndex) as string;
|
||||||
|
|
||||||
|
const fullResponse = !!options.fullResponse as boolean;
|
||||||
|
|
||||||
if (responseFormat === 'file') {
|
if (responseFormat === 'file') {
|
||||||
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
|
const dataPropertyName = this.getNodeParameter('dataPropertyName', 0) as string;
|
||||||
|
|
||||||
@@ -853,23 +875,22 @@ export class HttpRequest implements INodeType {
|
|||||||
|
|
||||||
const fileName = (url).split('/').pop();
|
const fileName = (url).split('/').pop();
|
||||||
|
|
||||||
|
|
||||||
if (fullResponse === true) {
|
if (fullResponse === true) {
|
||||||
const returnItem: IDataObject = {};
|
const returnItem: IDataObject = {};
|
||||||
for (const property of fullReponseProperties) {
|
for (const property of fullReponseProperties) {
|
||||||
if (property === 'body') {
|
if (property === 'body') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
returnItem[property] = response[property];
|
returnItem[property] = response![property];
|
||||||
}
|
}
|
||||||
|
|
||||||
newItem.json = returnItem;
|
newItem.json = returnItem;
|
||||||
|
|
||||||
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(response.body, fileName);
|
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(response!.body, fileName);
|
||||||
} else {
|
} else {
|
||||||
newItem.json = items[itemIndex].json;
|
newItem.json = items[itemIndex].json;
|
||||||
|
|
||||||
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(response, fileName);
|
newItem.binary![dataPropertyName] = await this.helpers.prepareBinaryData(response!, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
items[itemIndex] = newItem;
|
items[itemIndex] = newItem;
|
||||||
@@ -880,11 +901,11 @@ export class HttpRequest implements INodeType {
|
|||||||
const returnItem: IDataObject = {};
|
const returnItem: IDataObject = {};
|
||||||
for (const property of fullReponseProperties) {
|
for (const property of fullReponseProperties) {
|
||||||
if (property === 'body') {
|
if (property === 'body') {
|
||||||
returnItem[dataPropertyName] = response[property];
|
returnItem[dataPropertyName] = response![property];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
returnItem[property] = response[property];
|
returnItem[property] = response![property];
|
||||||
}
|
}
|
||||||
returnItems.push({ json: returnItem });
|
returnItems.push({ json: returnItem });
|
||||||
} else {
|
} else {
|
||||||
@@ -899,7 +920,7 @@ export class HttpRequest implements INodeType {
|
|||||||
if (fullResponse === true) {
|
if (fullResponse === true) {
|
||||||
const returnItem: IDataObject = {};
|
const returnItem: IDataObject = {};
|
||||||
for (const property of fullReponseProperties) {
|
for (const property of fullReponseProperties) {
|
||||||
returnItem[property] = response[property];
|
returnItem[property] = response![property];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responseFormat === 'json' && typeof returnItem.body === 'string') {
|
if (responseFormat === 'json' && typeof returnItem.body === 'string') {
|
||||||
|
|||||||
Reference in New Issue
Block a user