From aa2945bcd60c17b3e8701b79d79827b1e233bf12 Mon Sep 17 00:00:00 2001 From: Alec Date: Wed, 4 Sep 2024 17:18:07 -0400 Subject: [PATCH] longer savant polling via backoff --- config/globals.js | 3 ++- modules/gameday.js | 4 +++- spec/gameday-spec.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config/globals.js b/config/globals.js index 4dd70d3..2da60df 100644 --- a/config/globals.js +++ b/config/globals.js @@ -63,7 +63,8 @@ module.exports = { 'other_out' ], SAVANT_POLLING_INTERVAL: 15000, - SAVANT_POLLING_ATTEMPTS: 15, + SAVANT_POLLING_ATTEMPTS: 10, + SAVANT_POLLING_BACKOFF_INCREASE: 5000, HOME_RUN_BALLPARKS_MIN_DISTANCE: 300, SLOW_POLL_INTERVAL: 300000, GAMEDAY_PING_INTERVAL: 10000, diff --git a/modules/gameday.js b/modules/gameday.js index 1ea319d..2405307 100644 --- a/modules/gameday.js +++ b/modules/gameday.js @@ -251,6 +251,7 @@ function notifySavantDataUnavailable (messages) { async function pollForSavantData (gamePk, playId, messages, hitDistance) { let attempts = 1; + let currentInterval = globals.SAVANT_POLLING_INTERVAL; const messageTrackers = messages.map(message => { return { id: message.id, done: false }; }); console.time('xBA: ' + playId); console.time('Bat Speed: ' + playId); @@ -273,7 +274,8 @@ async function pollForSavantData (gamePk, playId, messages, hitDistance) { await module.exports.processMatchingPlay(matchingPlay, messages, messageTrackers, playId, hitDistance); } attempts ++; - setTimeout(async () => { await pollingFunction(); }, globals.SAVANT_POLLING_INTERVAL); + currentInterval = currentInterval + globals.SAVANT_POLLING_BACKOFF_INCREASE; + setTimeout(async () => { await pollingFunction(); }, currentInterval); } else { LOGGER.debug('max savant polling attempts reached for: ' + playId); notifySavantDataUnavailable(messages); diff --git a/spec/gameday-spec.js b/spec/gameday-spec.js index ce80f65..9f4e439 100644 --- a/spec/gameday-spec.js +++ b/spec/gameday-spec.js @@ -75,7 +75,7 @@ describe('gameday', () => { }); jasmine.clock().install(); await gameday.pollForSavantData(1, 'xyz', [{}, {}], 350); - jasmine.clock().tick(globals.SAVANT_POLLING_INTERVAL); + jasmine.clock().tick(globals.SAVANT_POLLING_INTERVAL + globals.SAVANT_POLLING_BACKOFF_INCREASE); expect(mlbAPIUtil.savantGameFeed).toHaveBeenCalledTimes(2); expect(gameday.processMatchingPlay).not.toHaveBeenCalled(); jasmine.clock().uninstall();