Compare commits
No commits in common. "21899b8a799106c36562067167566451a81b6c73" and "d5a19ca9c3c17b8bfbfd9ca160654e9283cd122b" have entirely different histories.
21899b8a79
...
d5a19ca9c3
@ -117,10 +117,6 @@ spec:
|
|||||||
value: firefly-user-sync
|
value: firefly-user-sync
|
||||||
- name: FIREFLY_USER_SYNC_WAIT_TIMEOUT_SEC
|
- name: FIREFLY_USER_SYNC_WAIT_TIMEOUT_SEC
|
||||||
value: "90"
|
value: "90"
|
||||||
- name: VAULTWARDEN_ADMIN_SESSION_TTL_SEC
|
|
||||||
value: "900"
|
|
||||||
- name: VAULTWARDEN_ADMIN_RATE_LIMIT_BACKOFF_SEC
|
|
||||||
value: "60"
|
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
containerPort: 8080
|
containerPort: 8080
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import http.server
|
import http.server
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@ -8,17 +7,15 @@ from time import time
|
|||||||
|
|
||||||
# Simple debounce to avoid hammering on bursts
|
# Simple debounce to avoid hammering on bursts
|
||||||
MIN_INTERVAL_SECONDS = 10
|
MIN_INTERVAL_SECONDS = 10
|
||||||
WAIT_TIMEOUT_SECONDS = float(os.environ.get("MAILU_SYNC_WAIT_TIMEOUT_SEC", "20"))
|
|
||||||
last_run = 0.0
|
last_run = 0.0
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
sync_done = threading.Event()
|
sync_done = threading.Event()
|
||||||
sync_done.set()
|
sync_done.set()
|
||||||
sync_running = False
|
sync_running = False
|
||||||
last_rc = None
|
|
||||||
|
|
||||||
|
|
||||||
def _run_sync_blocking() -> int:
|
def _run_sync_blocking() -> int:
|
||||||
global last_run, sync_running, last_rc
|
global last_run, sync_running
|
||||||
with lock:
|
with lock:
|
||||||
if sync_running:
|
if sync_running:
|
||||||
return 0
|
return 0
|
||||||
@ -30,7 +27,6 @@ def _run_sync_blocking() -> int:
|
|||||||
proc = subprocess.run(["python", "/app/sync.py"], check=False)
|
proc = subprocess.run(["python", "/app/sync.py"], check=False)
|
||||||
rc = int(proc.returncode)
|
rc = int(proc.returncode)
|
||||||
print(f"mailu-sync-listener: sync completed rc={rc}", flush=True)
|
print(f"mailu-sync-listener: sync completed rc={rc}", flush=True)
|
||||||
last_rc = rc
|
|
||||||
return rc
|
return rc
|
||||||
finally:
|
finally:
|
||||||
with lock:
|
with lock:
|
||||||
@ -70,20 +66,16 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
if wait:
|
if wait:
|
||||||
with lock:
|
with lock:
|
||||||
already_running = sync_running
|
already_running = sync_running
|
||||||
|
if already_running:
|
||||||
|
sync_done.wait(timeout=120)
|
||||||
|
with lock:
|
||||||
|
still_running = sync_running
|
||||||
|
self.send_response(200 if not still_running else 503)
|
||||||
|
self.end_headers()
|
||||||
|
return
|
||||||
|
|
||||||
if not already_running:
|
rc = _run_sync_blocking()
|
||||||
_trigger_sync_async()
|
self.send_response(200 if rc == 0 else 500)
|
||||||
|
|
||||||
sync_done.wait(timeout=WAIT_TIMEOUT_SECONDS)
|
|
||||||
with lock:
|
|
||||||
still_running = sync_running
|
|
||||||
rc = last_rc
|
|
||||||
|
|
||||||
if still_running:
|
|
||||||
# Avoid blocking callers while a sync is in flight.
|
|
||||||
self.send_response(200)
|
|
||||||
else:
|
|
||||||
self.send_response(200 if rc == 0 else 500)
|
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user