Some checks failed
Deploy / deploy (push) Failing after 51s
Drives massprice.tcgplayer.com's Run Rule action per-rule on a user-configured schedule (multiple times/day, day-of-week toggles), replacing MassPrice's native scheduler (capped at 15 schedules account-wide, one run/day, with observed clock drift). Deployed via Forgejo push-to-deploy on Unraid, matching arr-summary/card-grader. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H6TgffxTvYhqxykAbVQg2v
35 lines
815 B
Python
35 lines
815 B
Python
"""Small JSON read/write helpers for the state files under DATA_DIR.
|
|
|
|
Every file is written via a temp-file + os.replace so a crash mid-write
|
|
never leaves a half-written JSON file behind for the next read.
|
|
"""
|
|
import json
|
|
import os
|
|
import threading
|
|
|
|
DATA_DIR = os.environ.get("DATA_DIR", "/data")
|
|
|
|
_lock = threading.Lock()
|
|
|
|
|
|
def _path(name):
|
|
return os.path.join(DATA_DIR, name)
|
|
|
|
|
|
def load(name, default):
|
|
path = _path(name)
|
|
with _lock:
|
|
if not os.path.exists(path):
|
|
return default
|
|
with open(path) as f:
|
|
return json.load(f)
|
|
|
|
|
|
def save(name, data):
|
|
path = _path(name)
|
|
with _lock:
|
|
os.makedirs(DATA_DIR, exist_ok=True)
|
|
tmp = path + ".tmp"
|
|
with open(tmp, "w") as f:
|
|
json.dump(data, f, indent=2)
|
|
os.replace(tmp, path)
|