@ultipa-graph/ultipa-node-sdk
Version:
NodeJS SDK for ultipa-server 4.0
54 lines • 2.4 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.retryHelper = void 0;
const types_1 = require("../types");
exports.retryHelper = {
getRetry: (commonReq) => {
let currentRetry = (commonReq === null || commonReq === void 0 ? void 0 : commonReq.retry) || {
max: 3,
current: 0
};
let nextRetry = Object.assign(Object.assign({}, currentRetry), { current: currentRetry.current + 1 });
return {
currentRetry,
nextRetry,
};
},
check: (conn, response, commonReq, graphSetName) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
let canRetry = false;
let { currentRetry, nextRetry } = exports.retryHelper.getRetry(commonReq);
let redirectHost = null;
if ([
types_1.ULTIPA.Code.RAFT_REDIRECT,
types_1.ULTIPA.Code.RAFT_LEADER_NOT_YET_ELECTED,
types_1.ULTIPA.Code.RAFT_NO_AVAILABLE_FOLLOWERS,
types_1.ULTIPA.Code.RAFT_NO_AVAILABLE_ALGO_SERVERS,
].includes((_a = response.status) === null || _a === void 0 ? void 0 : _a.code)) {
if (currentRetry.current < currentRetry.max) {
redirectHost = (_b = response.status.clusterInfo) === null || _b === void 0 ? void 0 : _b.redirect;
let refresh = yield conn.refreshRaftLeader(redirectHost, {
graphSetName,
});
if (refresh) {
canRetry = true;
}
}
}
return {
canRetry,
currentRetry,
nextRetry,
};
})
};
//# sourceMappingURL=raft.retry.js.map