🎨 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:
GeoffreyCoulaud
2023-06-10 12:03:16 +02:00
parent c9a96f5eec
commit e7fd01f509
8 changed files with 14 additions and 14 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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