From c4059d3ca06a458ce14a4ed570237a6c21b498ec Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Mon, 4 Dec 2023 21:35:16 -0800 Subject: [PATCH 1/3] catch gpa fail --- src/index.ts | 16 +++++++++++----- src/publishers/dlobPublisher.ts | 21 +++++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 896462f..6205ddc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -289,11 +289,17 @@ const main = async () => { const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => { setTimeout(() => { const startFetch = Date.now(); - dlobProvider.fetch().then(() => { - gpaFetchDurationHistogram.record(Date.now() - startFetch); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - recursiveFetch(); - }); + dlobProvider + .fetch() + .then(() => { + gpaFetchDurationHistogram.record(Date.now() - startFetch); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + recursiveFetch(); + }) + .catch(() => { + logger.error('Failed to fetch GPA'); + recursiveFetch(); + }); }, delay); }; recursiveFetch(); diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 03fc706..9f7d311 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -30,6 +30,7 @@ import { getDLOBProviderFromOrderSubscriber, getDLOBProviderFromUserMap, } from '../dlobProvider'; +import FEATURE_FLAGS from '../utils/featureFlags'; require('dotenv').config(); const stateCommitment: Commitment = 'processed'; @@ -229,10 +230,22 @@ const main = async () => { spotMarketSubscribers: MARKET_SUBSCRIBERS, }); await dlobSubscriber.subscribe(); - if (useWebsocket) { - setInterval(async () => { - await dlobProvider.fetch(); - }, WS_FALLBACK_FETCH_INTERVAL); + if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) { + const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => { + setTimeout(() => { + dlobProvider + .fetch() + .then(() => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + recursiveFetch(); + }) + .catch(() => { + logger.error('Failed to fetch GPA'); + recursiveFetch(); + }); + }, delay); + }; + recursiveFetch(); } console.log('DLOBSubscriber Publishing Messages'); From 05a1a92598498779f04a6ea60b2db4553cf52e47 Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Mon, 4 Dec 2023 21:40:49 -0800 Subject: [PATCH 2/3] use finally --- src/index.ts | 5 +++-- src/publishers/dlobPublisher.ts | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6205ddc..4a1127b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -293,11 +293,12 @@ const main = async () => { .fetch() .then(() => { gpaFetchDurationHistogram.record(Date.now() - startFetch); - // eslint-disable-next-line @typescript-eslint/no-unused-vars - recursiveFetch(); }) .catch(() => { logger.error('Failed to fetch GPA'); + }) + .finally(() => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars recursiveFetch(); }); }, delay); diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 9f7d311..1a3e317 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -235,12 +235,11 @@ const main = async () => { setTimeout(() => { dlobProvider .fetch() - .then(() => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - recursiveFetch(); - }) .catch(() => { logger.error('Failed to fetch GPA'); + }) + .finally(() => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars recursiveFetch(); }); }, delay); From ff8f2f2f13a86adb4a1b06f73af4c606236eb04c Mon Sep 17 00:00:00 2001 From: Nour Alharithi Date: Tue, 5 Dec 2023 09:23:04 -0800 Subject: [PATCH 3/3] add conosle log --- src/index.ts | 3 ++- src/publishers/dlobPublisher.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 4a1127b..83a0197 100644 --- a/src/index.ts +++ b/src/index.ts @@ -294,8 +294,9 @@ const main = async () => { .then(() => { gpaFetchDurationHistogram.record(Date.now() - startFetch); }) - .catch(() => { + .catch((e) => { logger.error('Failed to fetch GPA'); + console.log(e); }) .finally(() => { // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index 1a3e317..3a86e1e 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -235,8 +235,9 @@ const main = async () => { setTimeout(() => { dlobProvider .fetch() - .catch(() => { + .catch((e) => { logger.error('Failed to fetch GPA'); + console.log(e); }) .finally(() => { // eslint-disable-next-line @typescript-eslint/no-unused-vars