Skip to content

Commit

Permalink
Use queue in ScrobblerProxy rather direct submit
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Jan 22, 2024
1 parent 0227601 commit 061dced
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions plextraktsync/trakt/ScrobblerProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from functools import cached_property
from typing import TYPE_CHECKING

from plextraktsync.decorators.rate_limit import rate_limit
from plextraktsync.factory import factory, logging

if TYPE_CHECKING:
Expand All @@ -12,32 +11,29 @@

class ScrobblerProxy:
"""
Proxy to Scrobbler that handles requests cache and rate limiting
Proxy to Scrobbler that queues requests to update trakt
"""

def __init__(self, scrobbler: Scrobbler, threshold=80):
self.scrobbler = scrobbler
self.threshold = threshold
self.logger = logging.getLogger("PlexTraktSync.ScrobblerProxy")

@rate_limit(retries=2)
def update(self, progress: float):
self.logger.debug(f"update({self.scrobbler.media}): {progress}")
return self.scrobbler.update(progress)
self.queue.scrobble_update((self.scrobbler, progress))

@rate_limit(retries=2)
def pause(self, progress: float):
self.logger.debug(f"pause({self.scrobbler.media}): {progress}")
return self.scrobbler.pause(progress)
self.queue.scrobble_pause((self.scrobbler, progress))

@rate_limit(retries=2)
def stop(self, progress: float):
if progress >= self.threshold:
self.logger.debug(f"stop({self.scrobbler.media}): {progress}")
return self.scrobbler.stop(progress)
self.queue.scrobble_stop((self.scrobbler, progress))
else:
self.logger.debug(f"pause({self.scrobbler.media}): {progress}")
return self.scrobbler.pause(progress)
self.queue.scrobble_pause((self.scrobbler, progress))

@cached_property
def queue(self):
Expand Down

0 comments on commit 061dced

Please sign in to comment.