From 0c37a46662ba249ed3d4026f0bd50763539abc5e Mon Sep 17 00:00:00 2001 From: shamsartem Date: Fri, 19 Apr 2024 17:06:52 +0200 Subject: [PATCH] feat: retry indexer client on local network (#911) --- src/lib/dealClient.ts | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/lib/dealClient.ts b/src/lib/dealClient.ts index c58d36ef5..dded6295b 100644 --- a/src/lib/dealClient.ts +++ b/src/lib/dealClient.ts @@ -125,6 +125,27 @@ export async function getDealCliClient() { const { DealCliClient } = await import("@fluencelabs/deal-ts-clients"); const env = await ensureChainEnv(); dealCliClient = new DealCliClient(env); + + if (env === "local") { + await setTryTimeout( + "check CLI Indexer client is ready", + async () => { + assert( + dealCliClient !== undefined, + "Unreachable. dealCliClient can't be undefined", + ); + + // By calling this method we ensure that the blockchain client is connected + await dealCliClient.getOffers({ ids: [] }); + }, + (err) => { + commandObj.error( + `CLI Indexer client is ready check failed when running dealCliClient.getOffers({ ids: [] }): ${stringifyUnknown(err)}`, + ); + }, + 1000 * 60, // 1 minute + ); + } } return dealCliClient; @@ -284,11 +305,11 @@ export async function sign< 1000 * 5, // 5 seconds 1000, (err: unknown) => { - // only retry data=null errors return !( err instanceof Error && - (err.message.includes("data=null") || - err.message.includes("connection error")) + ["data=null", "connection error", "connection closed"].some((msg) => { + return err.message.includes(msg); + }) ); }, );