async uploadToBlobWithRetry()

in packages/azure-kusto-ingest/src/ingestClientBase.ts [122:159]


    async uploadToBlobWithRetry(
        descriptor: string | Blob | ArrayBuffer | StreamDescriptor,
        blobName: string,
        maxRetries: number = KustoIngestClientBase.MaxNumberOfRetryAttempts,
    ): Promise<string> {
        const containers = await this.resourceManager.getContainers();

        if (containers == null || containers.length === 0) {
            throw new Error("Failed to get containers");
        }

        const retryCount = Math.min(maxRetries, containers.length);

        // Go over all containers and try to upload the file to the first one that succeeds
        for (let i = 0; i < retryCount; i++) {
            const containerClient = new ContainerClient(containers[i].uri);
            const blockBlobClient = containerClient.getBlockBlobClient(blobName);
            try {
                if (typeof descriptor == "string") {
                    await blockBlobClient.uploadFile(descriptor);
                } else if (descriptor instanceof StreamDescriptor) {
                    if (descriptor.stream instanceof Buffer) {
                        await blockBlobClient.uploadData(descriptor.stream as Buffer);
                    } else {
                        await blockBlobClient.uploadStream(descriptor.stream as Readable);
                    }
                } else {
                    await blockBlobClient.uploadData(descriptor);
                }
                this.resourceManager.reportResourceUsageResult(containerClient.accountName, true);
                return blockBlobClient.url;
            } catch (ex) {
                this.resourceManager.reportResourceUsageResult(containerClient.accountName, false);
            }
        }

        throw new Error("Failed to upload to blob.");
    }