mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
fix(core): Add retry mechanism to tools (#16667)
This commit is contained in:
@@ -9,6 +9,7 @@ import merge from 'lodash/merge';
|
||||
|
||||
import { ALPHABET } from './constants';
|
||||
import { ApplicationError } from './errors/application.error';
|
||||
import { ExecutionCancelledError } from './errors/execution-cancelled.error';
|
||||
import type { BinaryFileType, IDisplayOptions, INodeProperties, JsonObject } from './interfaces';
|
||||
|
||||
const readStreamClasses = new Set(['ReadStream', 'Readable', 'ReadableStream']);
|
||||
@@ -199,6 +200,23 @@ export const sleep = async (ms: number): Promise<void> =>
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
|
||||
export const sleepWithAbort = async (ms: number, abortSignal?: AbortSignal): Promise<void> =>
|
||||
await new Promise((resolve, reject) => {
|
||||
if (abortSignal?.aborted) {
|
||||
reject(new ExecutionCancelledError(''));
|
||||
return;
|
||||
}
|
||||
|
||||
const timeout = setTimeout(resolve, ms);
|
||||
|
||||
const abortHandler = () => {
|
||||
clearTimeout(timeout);
|
||||
reject(new ExecutionCancelledError(''));
|
||||
};
|
||||
|
||||
abortSignal?.addEventListener('abort', abortHandler, { once: true });
|
||||
});
|
||||
|
||||
export function fileTypeFromMimeType(mimeType: string): BinaryFileType | undefined {
|
||||
if (mimeType.startsWith('application/json')) return 'json';
|
||||
if (mimeType.startsWith('text/html')) return 'html';
|
||||
|
||||
Reference in New Issue
Block a user