fix(savetv): verhindere parallele NAS-Syncs

This commit is contained in:
root 2026-04-25 18:02:10 +02:00
parent ba9c55a916
commit 9731068a01

View file

@ -3,7 +3,7 @@
SaveTV NAS Sync
Wartet 12h ± 0-30min nach Download auf Hetzner bevor Datei auf NAS kommt.
"""
import os, json, time, random, urllib.request, urllib.parse, urllib.error, email.utils
import os, json, time, random, fcntl, urllib.request, urllib.parse, urllib.error, email.utils
from datetime import datetime
ZIEL = "/mnt/nas/Filme zum nachbearbeiten"
@ -11,6 +11,7 @@ BASE = "http://138.201.84.95:9443/files"
API = "http://138.201.84.95:9443/api/films"
CALLBACK = "http://138.201.84.95:9443/api/nas_synced"
LOG = "/var/log/savetv_sync.log"
LOCKFILE = "/tmp/savetv_sync.lock"
MIN_ALTER_H = 24
JITTER_MIN = 30 # ± bis zu 30 Minuten Zufall
@ -115,4 +116,10 @@ def sync():
log(f"Fertig. {kopiert} neue Filme kopiert.")
if __name__ == "__main__":
sync()
with open(LOCKFILE, "w") as lock:
try:
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
except BlockingIOError:
log("Sync läuft bereits, überspringe diesen Start.")
raise SystemExit(0)
sync()