Fix main_v2 bridge and pipeline regressions
This commit is contained in:
+19
-14
@@ -7,6 +7,21 @@ import os
|
||||
|
||||
INGEST_URL = "https://emiapi.reynafamily.com/live-captions/ingest"
|
||||
|
||||
def post_with_retries(payload, timeout, max_attempts=3):
|
||||
delay = 1
|
||||
for attempt in range(1, max_attempts + 1):
|
||||
try:
|
||||
response = requests.post(INGEST_URL, json=payload, timeout=timeout)
|
||||
if response.status_code == 200:
|
||||
return True
|
||||
print(f"[Distribute Error] {response.status_code} on attempt {attempt}/{max_attempts}.")
|
||||
except Exception as exc:
|
||||
print(f"[Distribute Error] {exc} on attempt {attempt}/{max_attempts}.")
|
||||
if attempt < max_attempts:
|
||||
time.sleep(delay)
|
||||
delay = min(delay * 2, 5)
|
||||
return False
|
||||
|
||||
def log_debug(message):
|
||||
try:
|
||||
with open("distribute_debug.log", "a") as f:
|
||||
@@ -31,8 +46,7 @@ def run_distribution(in_queue, args):
|
||||
sys.stdout.write(f"\r\033[K[DRAFT]: {draft_text}")
|
||||
sys.stdout.flush()
|
||||
if args.ingest:
|
||||
try: requests.post(INGEST_URL, json={"draft": draft_text}, timeout=2)
|
||||
except: pass
|
||||
post_with_retries({"draft": draft_text}, timeout=2, max_attempts=2)
|
||||
continue
|
||||
|
||||
# Finalized segment
|
||||
@@ -75,18 +89,9 @@ def run_distribution(in_queue, args):
|
||||
should_send = False
|
||||
|
||||
if should_send:
|
||||
delay, max_delay, success = 1, 15, False
|
||||
while not success:
|
||||
try:
|
||||
response = requests.post(INGEST_URL, json=ingest_payload, timeout=5)
|
||||
if response.status_code == 200: success = True
|
||||
else: print(f"[Distribute Error] {response.status_code}. Retrying...")
|
||||
except Exception as e:
|
||||
print(f"[Distribute Error] {e}. Retrying...")
|
||||
|
||||
if not success:
|
||||
time.sleep(delay)
|
||||
delay = min(delay * 2, max_delay)
|
||||
success = post_with_retries(ingest_payload, timeout=5, max_attempts=3)
|
||||
if not success:
|
||||
log_debug(f"Dropped ingest payload after retries: {ingest_payload}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"[Distribute] Error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user