diff --git a/audiotagloader/cache.py b/audiotagloader/cache.py index 71630b5..119df09 100644 --- a/audiotagloader/cache.py +++ b/audiotagloader/cache.py @@ -32,22 +32,23 @@ def wrapper(*args, **kwargs) -> Any: key = hash_key(func.__name__, args, kwargs) print("HASH KEY:", key) - - try: - data = redis_client.get(key) - - if data is not None and issubclass(return_type, BaseModel): - return return_type.model_validate_json(data.decode()) - elif data is not None: - arg_type = get_args(return_type) - current_type = arg_type[0] - print("load from redis") - return [ - current_type.model_validate(item) - for item in json.loads(data.decode()) - ] - except Exception as e: - raise e + if not UPDATE_CACHE: + try: + data = redis_client.get(key) + + if data is not None: + if issubclass(return_type, BaseModel): + return return_type.model_validate_json(data.decode()) + else: + arg_type = get_args(return_type) + current_type = arg_type[0] + print("load from redis") + return [ + current_type.model_validate(item) + for item in json.loads(data.decode()) + ] + except Exception as e: + raise e res = func(*args, **kwargs) print("load from api") diff --git a/audiotagloader/output.py b/audiotagloader/output.py index 642f896..a402621 100644 --- a/audiotagloader/output.py +++ b/audiotagloader/output.py @@ -35,6 +35,9 @@ def wrapper(*args, **kwargs) -> tuple[Album, Image, Tracklist]: with open((dir / "tags.txt"), "w") as fp: fp.write("\n".join(table)) fp.write("\n") + + print(f"{album.year} - {album.artist} - {album.title}") + return res return wrapper diff --git a/cache/deploy_wo_compose.sh b/cache/deploy_wo_compose.sh new file mode 100644 index 0000000..c5fd139 --- /dev/null +++ b/cache/deploy_wo_compose.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +CONTAINER_NAME="AudioTagLoader" +IMAGE="redis:7-alpine" +HOST_PORT=6379 +CONTAINER_PORT=6379 +REDIS_PASSWORD="REDIS_PASSWORD" + +HOST_DATA_DIR="/volume1/docker/Containers/AudioTagLoader/data" +HOST_CONF_FILE="/volume1/docker/Containers/AudioTagLoader/redis.conf" + +docker run -d \ + --name "$CONTAINER_NAME" \ + --restart unless-stopped \ + -p ${HOST_PORT}:6379 \ + -v "${HOST_DATA_DIR}:/data" \ + -v "${1}:/redis.conf:ro" \å + "$IMAGE" \ + redis-server /redis.conf --requirepass "$REDIS_PASSWORD" \ No newline at end of file