Skip to content
Merged

Dev #24

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions audiotagloader/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions audiotagloader/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 19 additions & 0 deletions cache/deploy_wo_compose.sh
Original file line number Diff line number Diff line change
@@ -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"
Loading