Spaces:
Running
Running
Update storage_handler.py
Browse files- storage_handler.py +21 -0
storage_handler.py
CHANGED
|
@@ -99,6 +99,27 @@ def ensure_bucket():
|
|
| 99 |
|
| 100 |
ensure_bucket()
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
# ------------------------------------------------------------------------
|
| 103 |
# Encryption / Decryption
|
| 104 |
# ------------------------------------------------------------------------
|
|
|
|
| 99 |
|
| 100 |
ensure_bucket()
|
| 101 |
|
| 102 |
+
# storage_handler.py – add after ensure_bucket() call at bottom of file
|
| 103 |
+
import threading
|
| 104 |
+
|
| 105 |
+
def _sync_bucket_interval():
|
| 106 |
+
"""
|
| 107 |
+
Periodic sync task: runs every 60 seconds.
|
| 108 |
+
Uses HfFileSystem which already writes directly to the bucket,
|
| 109 |
+
so this function logs stats and verifies the connection is alive.
|
| 110 |
+
"""
|
| 111 |
+
def _sync():
|
| 112 |
+
while True:
|
| 113 |
+
time.sleep(60)
|
| 114 |
+
try:
|
| 115 |
+
stats = get_storage_stats()
|
| 116 |
+
logger.info(f"📦 Bucket sync heartbeat — {stats['file_count']} files / {stats['total_size_mb']} MB")
|
| 117 |
+
except Exception as e:
|
| 118 |
+
logger.warning(f"⚠️ Bucket sync heartbeat failed: {e}")
|
| 119 |
+
t = threading.Thread(target=_sync, daemon=True)
|
| 120 |
+
t.start()
|
| 121 |
+
|
| 122 |
+
_sync_bucket_interval()
|
| 123 |
# ------------------------------------------------------------------------
|
| 124 |
# Encryption / Decryption
|
| 125 |
# ------------------------------------------------------------------------
|