From 41e607c9952b7c05314ab3655de9ce1ea288cda6 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Tue, 30 Jan 2024 13:40:52 -0500 Subject: [PATCH] refactor(scrobbler): Use simpler method for handling queued scrobbles #130 --- src/backend/scrobblers/AbstractScrobbleClient.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/backend/scrobblers/AbstractScrobbleClient.ts b/src/backend/scrobblers/AbstractScrobbleClient.ts index bd37f9aa..565c4e78 100644 --- a/src/backend/scrobblers/AbstractScrobbleClient.ts +++ b/src/backend/scrobblers/AbstractScrobbleClient.ts @@ -581,7 +581,7 @@ ${closestMatch.breakdowns.join('\n')}`, {leaf: ['Dupe Check']}); if (this.lastScrobbleCheck.unix() < this.getLatestQueuePlayDate().unix()) { await this.refreshScrobbles(); } - const currQueuedPlay = this.queuedScrobbles[0]; + const currQueuedPlay = this.queuedScrobbles.shift(); const [timeFrameValid, timeFrameValidLog] = this.timeFrameIsValid(currQueuedPlay.play); if (timeFrameValid && !(await this.alreadyScrobbled(currQueuedPlay.play))) { try { @@ -593,20 +593,14 @@ ${closestMatch.breakdowns.join('\n')}`, {leaf: ['Dupe Check']}); this.addDeadLetterScrobble(currQueuedPlay, e); this.logger.warn(new ErrorWithCause(`Could not scrobble ${buildTrackString(currQueuedPlay.play)} from Source '${currQueuedPlay.source}' but error was not show stopping. Adding scrobble to Dead Letter Queue and will retry on next heartbeat.`, {cause: e})); } else { - const processError = new ErrorWithCause('Error occurred while trying to scrobble', {cause: e}); - //this.logger.error(processError); - throw processError; + this.queuedScrobbles.unshift(currQueuedPlay); + throw new ErrorWithCause('Error occurred while trying to scrobble', {cause: e}); } } } else if (!timeFrameValid) { this.logger.debug(`Will not scrobble ${buildTrackString(currQueuedPlay.play)} from Source '${currQueuedPlay.source}' because it ${timeFrameValidLog}`); } - // processing play may have changed index while we were scrobbling - const pIndex = this.queuedScrobbles.findIndex(x => x.id === currQueuedPlay.id); - if (pIndex !== -1) { - this.emitEvent('scrobbleDequeued', {queuedScrobble: currQueuedPlay}) - this.queuedScrobbles.splice(pIndex, 1); - } + this.emitEvent('scrobbleDequeued', {queuedScrobble: currQueuedPlay}) } await sleep(this.scrobbleSleep); }