Skip to content

Commit

Permalink
playlists: infinite retries for background playlist refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
3np committed Jun 16, 2022
1 parent 3d4b07c commit 4fd8afe
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions mopidy_spotify/playlists.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import threading
import time

from mopidy import backend
from mopidy.core import listener
Expand Down Expand Up @@ -64,22 +65,24 @@ def refresh(self):
logger.info("Refreshing Spotify playlists")

def refresher():
try:
with utils.time_logger("playlists.refresh()", logging.DEBUG):
count = 0
for playlist_ref in self._get_flattened_playlist_refs(force_refresh=True):
self._get_playlist(playlist_ref.uri)
count += 1
logger.info(f"Refreshed {count} Spotify playlists")

listener.CoreListener.send("playlists_loaded")
self._loaded = True
except Exception as e:
logger.exception(
f"An error occurred while refreshing Spotify playlists: {e}"
)
finally:
self._refreshing = False
self._loaded = False
while not self._loaded:
try:
with utils.time_logger("playlists.refresh()", logging.DEBUG):
count = 0
for playlist_ref in self._get_flattened_playlist_refs(force_refresh=True):
self._get_playlist(playlist_ref.uri)
count += 1
logger.info(f"Refreshed {count} Spotify playlists")

listener.CoreListener.send("playlists_loaded")
self._refreshing = False
self._loaded = True
except Exception as e:
logger.exception(
f"An error occurred while refreshing Spotify playlists, retrying: {e}"
)
time.sleep(3000)

thread = threading.Thread(target=refresher)
thread.daemon = True
Expand Down

0 comments on commit 4fd8afe

Please sign in to comment.