Skip to content

Commit

Permalink
feat(HTTP Request Node): Interval Between Requests option for paginat…
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency committed Jan 4, 2024
1 parent b50d805 commit 270328c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import {
ExecutionBaseError,
jsonParse,
ApplicationError,
sleep,
} from 'n8n-workflow';
import type { Token } from 'oauth-1.0a';
import clientOAuth1 from 'oauth-1.0a';
Expand Down Expand Up @@ -2748,6 +2749,9 @@ const getRequestHelperFunctions = (
) as boolean;

if (makeAdditionalRequest) {
if (paginationOptions.requestInterval) {
await sleep(paginationOptions.requestInterval);
}
if (tempResponseData.statusCode < 200 || tempResponseData.statusCode >= 300) {
// We have it configured to let all requests pass no matter the response code
// via "requestOptions.simple = false" to not by default fail if it is for example
Expand Down
19 changes: 19 additions & 0 deletions packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,23 @@ export class HttpRequestV3 implements INodeType {
default: 100,
description: 'Maximum amount of request to be make',
},
{
// eslint-disable-next-line n8n-nodes-base/node-param-display-name-miscased
displayName: 'Interval Between Requests (ms)',
name: 'requestInterval',
type: 'number',
displayOptions: {
hide: {
paginationMode: ['off'],
},
},
default: 0,
description: 'Time in milliseconds to wait between requests',
hint: 'At 0 no delay will be added',
typeOptions: {
minValue: 0,
},
},
],
},
],
Expand Down Expand Up @@ -1272,6 +1289,7 @@ export class HttpRequestV3 implements INodeType {
completeExpression: string;
limitPagesFetched: boolean;
maxRequests: number;
requestInterval: number;
};

for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
Expand Down Expand Up @@ -1653,6 +1671,7 @@ export class HttpRequestV3 implements INodeType {
const paginationData: PaginationOptions = {
continue: continueExpression,
request: {},
requestInterval: pagination.requestInterval,
};

if (pagination.paginationMode === 'updateAParameterInEachRequest') {
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ export interface PaginationOptions {
binaryResult?: boolean;
continue: boolean | string;
request: IRequestOptionsSimplifiedAuth;
requestInterval: number;
maxRequests?: number;
}

Expand Down

0 comments on commit 270328c

Please sign in to comment.