Skip to content

Commit

Permalink
Merge pull request #42 from AlecM33/polling-back-off
Browse files Browse the repository at this point in the history
longer savant polling via backoff
  • Loading branch information
AlecM33 authored Sep 4, 2024
2 parents d2e7abb + aa2945b commit fafc530
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion config/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion modules/gameday.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion spec/gameday-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fafc530

Please sign in to comment.