Skip to content

Commit 71dca90

Browse files
Improve routine lock.
1 parent 50bd43c commit 71dca90

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/admin.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import json
2626
import logging
27+
import os
2728
import random
2829
import time
2930
import zipfile
@@ -280,13 +281,13 @@ def refresh_has_metakg():
280281
refresh = refresh_document
281282
check = check_uptime
282283

283-
# only one process should perform backup routines
284-
_lock = FileLock(".lock", timeout=0)
285-
286284

287285
def routine(no_backup=False, format="zip"):
288286
logger = logging.getLogger("routine")
289287

288+
# only one process should perform backup routines
289+
_lock = FileLock(".lock", timeout=0)
290+
290291
# Add jitter: random delay between 100 and 500 milliseconds (adjust range as needed)
291292
jitter_ms = random.uniform(100, 500) # Jitter in milliseconds
292293
jitter_seconds = jitter_ms / 1000 # Convert milliseconds to seconds
@@ -326,6 +327,15 @@ def routine(no_backup=False, format="zip"):
326327
_lock.release()
327328
logger.info("Schedule lock released successfully.")
328329

330+
# Try to delete the .lock file manually if it still exists
331+
lock_file_path = ".lock"
332+
if os.path.exists(lock_file_path):
333+
try:
334+
os.remove(lock_file_path)
335+
logger.info(".lock file manually deleted.")
336+
except Exception as e:
337+
logger.warning(f"Could not delete .lock file: {e}")
338+
329339

330340
if __name__ == "__main__":
331341
restore_from_s3()

0 commit comments

Comments
 (0)