add timeouts to config

This commit is contained in:
DieMyst 2023-02-23 14:30:49 +04:00
parent b06ca3a3c8
commit 6f7d31b960
3 changed files with 11 additions and 7 deletions

View File

@ -11,5 +11,7 @@
"counterPeerId": null, "counterPeerId": null,
"quorumServiceId": null, "quorumServiceId": null,
"quorumPeerId": null, "quorumPeerId": null,
"quorumNumber": 2 "quorumNumber": 2,
"quorumTimeout": null,
"requestTimeout": null
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@fluencelabs/aqua-eth-gateway", "name": "@fluencelabs/aqua-eth-gateway",
"version": "0.0.14", "version": "0.0.15",
"description": "", "description": "",
"main": "src/index.js", "main": "src/index.js",
"type": "module", "type": "module",

View File

@ -65,7 +65,7 @@ registerCounter("counter", {
}) })
function findSameResults(results, minNum) { function findSameResults(results, minNum) {
const resultCounts = results.filter((obj) => obj.success).map((obj) => obj.value).reduce(function(i, v, idx) { const resultCounts = results.filter((obj) => obj.success).map((obj) => obj.value).reduce(function(i, v) {
if (i[v] === undefined) { if (i[v] === undefined) {
i[v] = 1 i[v] = 1
} else { } else {
@ -106,19 +106,21 @@ const counterPeerId = config.counterPeerId || peerId
const quorumServiceId = config.quorumServiceId || 'quorum' const quorumServiceId = config.quorumServiceId || 'quorum'
const quorumPeerId = config.quorumPeerId || peerId const quorumPeerId = config.quorumPeerId || peerId
const quorumNumber = config.quorumNumber || 2 const quorumNumber = config.quorumNumber || 2
const quorumTimeout = config.quorumTimeout || 10000
const requestTimeoutConfig = config.requestTimeout ? {ttl: config.requestTimeout} : null
async function methodHandler(req, method) { async function methodHandler(req, method) {
console.log(`Receiving request '${method}'`); console.log(`Receiving request '${method}'`);
let result; let result;
if (!config.mode || config.mode === "random") { if (!config.mode || config.mode === "random") {
result = await randomLoadBalancingEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId); result = await randomLoadBalancingEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId, requestTimeoutConfig);
} else if (config.mode === "round-robin") { } else if (config.mode === "round-robin") {
console.log("peerId: " + peerId) console.log("peerId: " + peerId)
result = await roundRobinEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId, counterServiceId, counterPeerId, result = await roundRobinEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId, counterServiceId, counterPeerId,
config.serviceId); config.serviceId, requestTimeoutConfig);
} else if (config.mode === "quorum") { } else if (config.mode === "quorum") {
result = await quorumEth(config.providers, config.quorumNumber, 5000, method, req.map((s) => JSON.stringify(s)), config.serviceId, quorumServiceId, quorumPeerId, result = await quorumEth(config.providers, quorumNumber, quorumTimeout, method, req.map((s) => JSON.stringify(s)), config.serviceId, quorumServiceId, quorumPeerId,
config.serviceId); config.serviceId, requestTimeoutConfig);
if (result.error) { if (result.error) {
return {error: result.error, results: result.results} return {error: result.error, results: result.results}