@azure/cosmos
Version:
Microsoft Azure Cosmos DB Service Node.js SDK for NOSQL API
69 lines (68 loc) • 2.76 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var bulkExecutionRetryPolicy_exports = {};
__export(bulkExecutionRetryPolicy_exports, {
BulkExecutionRetryPolicy: () => BulkExecutionRetryPolicy
});
module.exports = __toCommonJS(bulkExecutionRetryPolicy_exports);
var import_helper = require("../common/helper.js");
var import_statusCodes = require("../common/statusCodes.js");
class BulkExecutionRetryPolicy {
retryAfterInMs;
retriesOn410;
MaxRetriesOn410 = 10;
SubstatusCodeBatchResponseSizeExceeded = 3402;
nextRetryPolicy;
constructor(nextRetryPolicy) {
this.nextRetryPolicy = nextRetryPolicy;
this.retriesOn410 = 0;
}
async shouldRetry(err, diagnosticNode) {
if (!err) {
return false;
}
if (err.code === import_statusCodes.StatusCodes.Gone) {
this.retriesOn410++;
if (this.retriesOn410 > this.MaxRetriesOn410) {
return false;
}
if (err.substatus === import_statusCodes.SubStatusCodes.PartitionKeyRangeGone || err.substatus === import_statusCodes.SubStatusCodes.CompletingSplit || err.substatus === import_statusCodes.SubStatusCodes.CompletingPartitionMigration) {
return true;
}
if (err.substatus === import_statusCodes.SubStatusCodes.NameCacheIsStale) {
return true;
}
}
if (err.code === import_statusCodes.StatusCodes.RequestEntityTooLarge && err.substatus === this.SubstatusCodeBatchResponseSizeExceeded) {
return true;
}
let shouldRetryForThrottle = false;
if (err.code === import_statusCodes.StatusCodes.TooManyRequests) {
const retryResult = await this.nextRetryPolicy.shouldRetry(err, diagnosticNode);
shouldRetryForThrottle = Array.isArray(retryResult) ? retryResult[0] : retryResult;
}
if (shouldRetryForThrottle) {
await (0, import_helper.sleep)(this.nextRetryPolicy.retryAfterInMs);
}
return shouldRetryForThrottle;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BulkExecutionRetryPolicy
});