h
This commit is contained in:
@@ -3,6 +3,8 @@ from __future__ import annotations
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from typing import Any, Iterator, Optional, Sequence, Tuple
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PipelineProgress:
|
||||
@@ -31,6 +33,7 @@ class PipelineProgress:
|
||||
) if hasattr(self._ctx,
|
||||
"get_live_progress") else None
|
||||
except Exception:
|
||||
logger.exception("Failed to get live progress UI from pipeline context")
|
||||
ui = None
|
||||
|
||||
pipe_idx: int = 0
|
||||
@@ -48,6 +51,7 @@ class PipelineProgress:
|
||||
if isinstance(maybe_idx, int):
|
||||
pipe_idx = int(maybe_idx)
|
||||
except Exception:
|
||||
logger.exception("Failed to determine pipe index from stage context")
|
||||
pipe_idx = 0
|
||||
|
||||
return ui, pipe_idx
|
||||
@@ -61,6 +65,7 @@ class PipelineProgress:
|
||||
if callable(begin):
|
||||
begin(int(pipe_idx), total_steps=int(total_steps))
|
||||
except Exception:
|
||||
logger.exception("Failed to call begin_pipe_steps on UI")
|
||||
return
|
||||
|
||||
def step(self, text: str) -> None:
|
||||
@@ -72,6 +77,7 @@ class PipelineProgress:
|
||||
if callable(adv):
|
||||
adv(int(pipe_idx), str(text))
|
||||
except Exception:
|
||||
logger.exception("Failed to advance pipe step on UI")
|
||||
return
|
||||
|
||||
def set_percent(self, percent: int) -> None:
|
||||
@@ -83,6 +89,7 @@ class PipelineProgress:
|
||||
if callable(set_pct):
|
||||
set_pct(int(pipe_idx), int(percent))
|
||||
except Exception:
|
||||
logger.exception("Failed to set pipe percent on UI")
|
||||
return
|
||||
|
||||
def set_status(self, text: str) -> None:
|
||||
@@ -94,6 +101,7 @@ class PipelineProgress:
|
||||
if callable(setter):
|
||||
setter(int(pipe_idx), str(text))
|
||||
except Exception:
|
||||
logger.exception("Failed to set pipe status text on UI")
|
||||
return
|
||||
|
||||
def clear_status(self) -> None:
|
||||
@@ -105,6 +113,7 @@ class PipelineProgress:
|
||||
if callable(clr):
|
||||
clr(int(pipe_idx))
|
||||
except Exception:
|
||||
logger.exception("Failed to clear pipe status text on UI")
|
||||
return
|
||||
|
||||
def begin_transfer(self, *, label: str, total: Optional[int] = None) -> None:
|
||||
@@ -116,6 +125,7 @@ class PipelineProgress:
|
||||
if callable(fn):
|
||||
fn(label=str(label or "transfer"), total=total)
|
||||
except Exception:
|
||||
logger.exception("Failed to begin transfer on UI")
|
||||
return
|
||||
|
||||
def update_transfer(
|
||||
@@ -133,6 +143,7 @@ class PipelineProgress:
|
||||
if callable(fn):
|
||||
fn(label=str(label or "transfer"), completed=completed, total=total)
|
||||
except Exception:
|
||||
logger.exception("Failed to update transfer on UI")
|
||||
return
|
||||
|
||||
def finish_transfer(self, *, label: str) -> None:
|
||||
@@ -144,6 +155,7 @@ class PipelineProgress:
|
||||
if callable(fn):
|
||||
fn(label=str(label or "transfer"))
|
||||
except Exception:
|
||||
logger.exception("Failed to finish transfer on UI")
|
||||
return
|
||||
|
||||
def begin_pipe(
|
||||
@@ -164,6 +176,7 @@ class PipelineProgress:
|
||||
items_preview=list(items_preview or []),
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Failed to begin pipe on UI")
|
||||
return
|
||||
|
||||
def on_emit(self, emitted: Any) -> None:
|
||||
@@ -178,6 +191,7 @@ class PipelineProgress:
|
||||
try:
|
||||
self._local_ui.on_emit(0, emitted)
|
||||
except Exception:
|
||||
logger.exception("Failed to call local UI on_emit")
|
||||
return
|
||||
|
||||
def ensure_local_ui(
|
||||
@@ -196,6 +210,7 @@ class PipelineProgress:
|
||||
"get_live_progress") else None
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Failed to check existing live progress from pipeline context")
|
||||
existing = None
|
||||
|
||||
if existing is not None:
|
||||
@@ -213,6 +228,7 @@ class PipelineProgress:
|
||||
self._ctx.set_live_progress(ui)
|
||||
self._local_attached = True
|
||||
except Exception:
|
||||
logger.exception("Failed to attach local UI to pipeline context")
|
||||
self._local_attached = False
|
||||
|
||||
try:
|
||||
@@ -223,11 +239,12 @@ class PipelineProgress:
|
||||
items_preview=list(items_preview or [])
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to begin_pipe on local UI")
|
||||
|
||||
self._local_ui = ui
|
||||
return True
|
||||
except Exception:
|
||||
logger.exception("Failed to create local PipelineLiveProgress UI")
|
||||
self._local_ui = None
|
||||
self._local_attached = False
|
||||
return False
|
||||
@@ -239,18 +256,18 @@ class PipelineProgress:
|
||||
try:
|
||||
self._local_ui.finish_pipe(0, force_complete=bool(force_complete))
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to finish local UI pipe")
|
||||
try:
|
||||
self._local_ui.stop()
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to stop local UI")
|
||||
finally:
|
||||
self._local_ui = None
|
||||
try:
|
||||
if self._local_attached and hasattr(self._ctx, "set_live_progress"):
|
||||
self._ctx.set_live_progress(None)
|
||||
except Exception:
|
||||
pass
|
||||
logger.exception("Failed to detach local progress from pipeline context")
|
||||
self._local_attached = False
|
||||
|
||||
@contextmanager
|
||||
|
||||
Reference in New Issue
Block a user