fix(musicseerr): implement thread-safe jobs saving with a write lock and unique temp files
Build and Push Docker Images / build (api) (push) Successful in 1m11s Details
Build and Push Docker Images / build (musicseerr) (push) Successful in 8m2s Details
Build and Push Docker Images / build (web) (push) Successful in 3m1s Details
Build and Push Docker Images / build (nextgen) (push) Successful in 12m41s Details
Build and Push Docker Images / build (worker) (push) Successful in 14m30s Details
Build and Push Docker Images / deploy (push) Successful in 14s Details

This commit is contained in:
fchinembiri 2026-07-11 22:09:38 +02:00
parent a1b6fd8011
commit e0ba21eb07
2 changed files with 23 additions and 14 deletions

View File

@ -19,14 +19,18 @@ import json
JOBS_FILE = "/remote-music/.musicseerr_jobs.json"
from tasks import JOBS_WRITE_LOCK
def save_jobs_db(jobs_dict):
try:
temp_file = JOBS_FILE + ".tmp"
with open(temp_file, "w") as f:
json.dump(jobs_dict, f, indent=2)
os.replace(temp_file, JOBS_FILE)
except Exception as e:
logger.error(f"Failed to save jobs database: {e}")
with JOBS_WRITE_LOCK:
try:
temp_file = f"{JOBS_FILE}.{uuid.uuid4()}.tmp"
with open(temp_file, "w") as f:
json.dump(jobs_dict, f, indent=2)
os.replace(temp_file, JOBS_FILE)
except Exception as e:
logger.error(f"Failed to save jobs database: {e}")
def load_jobs_db():
if os.path.exists(JOBS_FILE):

View File

@ -20,14 +20,19 @@ logger = logging.getLogger("musicseerr-tasks")
JOBS_FILE = "/remote-music/.musicseerr_jobs.json"
JOBS_WRITE_LOCK = threading.Lock()
def save_jobs(jobs_dict):
try:
temp_file = JOBS_FILE + ".tmp"
with open(temp_file, "w") as f:
json.dump(jobs_dict, f, indent=2)
os.replace(temp_file, JOBS_FILE)
except Exception as e:
logger.error(f"Failed to save jobs database: {e}")
with JOBS_WRITE_LOCK:
try:
import uuid
temp_file = f"{JOBS_FILE}.{uuid.uuid4()}.tmp"
with open(temp_file, "w") as f:
json.dump(jobs_dict, f, indent=2)
os.replace(temp_file, JOBS_FILE)
except Exception as e:
logger.error(f"Failed to save jobs database: {e}")
def move_new_files_to_dest(temp_dir: str, dest_dir: str) -> list:
moved = []