🎨 Made manager attributes more flexible
Changed run_after, retryable_on and continue_on to be type Container. We don't need them to be sets. The performance gain of sets over small tuples is nonexistant for in checks and the syntax is more verbose.
This commit is contained in:
@@ -8,7 +8,7 @@ from src.store.managers.manager import Manager
|
||||
class DisplayManager(Manager):
|
||||
"""Manager in charge of adding a game to the UI"""
|
||||
|
||||
run_after = set((SteamAPIManager, SGDBManager))
|
||||
run_after = (SteamAPIManager, SGDBManager)
|
||||
|
||||
def manager_logic(self, game: Game, _additional_data: dict) -> None:
|
||||
# TODO decouple a game from its widget
|
||||
|
||||
@@ -6,7 +6,7 @@ from src.store.managers.steam_api_manager import SteamAPIManager
|
||||
class FileManager(AsyncManager):
|
||||
"""Manager in charge of saving a game to a file"""
|
||||
|
||||
run_after = set((SteamAPIManager,))
|
||||
run_after = (SteamAPIManager,)
|
||||
|
||||
def manager_logic(self, game: Game, _additional_data: dict) -> None:
|
||||
game.save()
|
||||
|
||||
@@ -17,8 +17,8 @@ from src.utils.save_cover import resize_cover, save_cover
|
||||
class ItchCoverManager(Manager):
|
||||
"""Manager in charge of downloading the game's cover from itch.io"""
|
||||
|
||||
run_after = set((LocalCoverManager,))
|
||||
retryable_on = set((HTTPError, SSLError))
|
||||
run_after = (LocalCoverManager,)
|
||||
retryable_on = (HTTPError, SSLError)
|
||||
|
||||
def manager_logic(self, game: Game, additional_data: dict) -> None:
|
||||
# Get the first matching cover url
|
||||
|
||||
@@ -9,7 +9,7 @@ from src.utils.save_cover import save_cover, resize_cover
|
||||
class LocalCoverManager(Manager):
|
||||
"""Manager in charge of adding the local cover image of the game"""
|
||||
|
||||
run_after = set((SteamAPIManager,))
|
||||
run_after = (SteamAPIManager,)
|
||||
|
||||
def manager_logic(self, game: Game, additional_data: dict) -> None:
|
||||
# Ensure that the cover path is in the additional data
|
||||
|
||||
@@ -2,7 +2,7 @@ import logging
|
||||
from abc import abstractmethod
|
||||
from threading import Lock
|
||||
from time import sleep
|
||||
from typing import Any, Callable
|
||||
from typing import Any, Callable, Container
|
||||
|
||||
from src.game import Game
|
||||
|
||||
@@ -16,11 +16,11 @@ class Manager:
|
||||
* May be retried on some specific error types
|
||||
"""
|
||||
|
||||
run_after: set[type["Manager"]] = set()
|
||||
run_after: Container[type["Manager"]] = tuple()
|
||||
blocking: bool = True
|
||||
|
||||
retryable_on: set[type[Exception]] = set()
|
||||
continue_on: set[type[Exception]] = set()
|
||||
retryable_on: Container[type[Exception]] = tuple()
|
||||
continue_on: Container[type[Exception]] = tuple()
|
||||
retry_delay: int = 3
|
||||
max_tries: int = 3
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ from src.utils.save_cover import resize_cover, save_cover
|
||||
class OnlineCoverManager(Manager):
|
||||
"""Manager that downloads game covers from URLs"""
|
||||
|
||||
run_after = set((LocalCoverManager,))
|
||||
retryable_on = set((HTTPError, SSLError))
|
||||
run_after = (LocalCoverManager,)
|
||||
retryable_on = (HTTPError, SSLError)
|
||||
|
||||
def manager_logic(self, game: Game, additional_data: dict) -> None:
|
||||
# Ensure that we have a cover to download
|
||||
|
||||
@@ -13,8 +13,8 @@ from src.utils.steamgriddb import SGDBAuthError, SGDBHelper
|
||||
class SGDBManager(AsyncManager):
|
||||
"""Manager in charge of downloading a game's cover from steamgriddb"""
|
||||
|
||||
run_after = set((SteamAPIManager, LocalCoverManager, ItchCoverManager))
|
||||
retryable_on = set((HTTPError, SSLError, ConnectionError, JSONDecodeError))
|
||||
run_after = (SteamAPIManager, LocalCoverManager, ItchCoverManager)
|
||||
retryable_on = (HTTPError, SSLError, ConnectionError, JSONDecodeError)
|
||||
|
||||
def manager_logic(self, game: Game, _additional_data: dict) -> None:
|
||||
try:
|
||||
|
||||
@@ -13,7 +13,7 @@ from src.utils.steam import (
|
||||
class SteamAPIManager(AsyncManager):
|
||||
"""Manager in charge of completing a game's data from the Steam API"""
|
||||
|
||||
retryable_on = set((HTTPError, SSLError))
|
||||
retryable_on = (HTTPError, SSLError)
|
||||
|
||||
steam_api_helper: SteamAPIHelper = None
|
||||
steam_rate_limiter: SteamRateLimiter = None
|
||||
|
||||
Reference in New Issue
Block a user