f
This commit is contained in:
@@ -47,8 +47,8 @@ class Worker:
|
||||
self.details = ""
|
||||
self.error_message = ""
|
||||
self.result = "pending"
|
||||
self._stdout_buffer = []
|
||||
self._steps_buffer = []
|
||||
self._stdout_buffer: list[str] = []
|
||||
self._steps_buffer: list[str] = []
|
||||
|
||||
def log_step(self, step_text: str) -> None:
|
||||
"""Log a step for this worker.
|
||||
@@ -108,18 +108,26 @@ class Worker:
|
||||
logger.error(f"Error getting steps for worker {self.id}: {e}")
|
||||
return ""
|
||||
|
||||
def update_progress(self, progress: str = "", details: str = "") -> None:
|
||||
def update_progress(self, progress: float | str = 0.0, details: str = "") -> None:
|
||||
"""Update worker progress.
|
||||
|
||||
Args:
|
||||
progress: Progress string (e.g., "50%")
|
||||
progress: Progress value (float) or textual like "50%"; will be coerced to float
|
||||
details: Additional details
|
||||
"""
|
||||
self.progress = progress
|
||||
self.progress = str(progress)
|
||||
self.details = details
|
||||
try:
|
||||
if self.manager:
|
||||
self.manager.update_worker(self.id, progress, details)
|
||||
# Normalize to a float value for the manager API (0-100)
|
||||
try:
|
||||
if isinstance(progress, str) and progress.endswith('%'):
|
||||
progress_value = float(progress.rstrip('%'))
|
||||
else:
|
||||
progress_value = float(progress)
|
||||
except Exception:
|
||||
progress_value = 0.0
|
||||
self.manager.update_worker(self.id, progress_value, details)
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating worker {self.id}: {e}")
|
||||
|
||||
@@ -165,7 +173,7 @@ class WorkerLoggingHandler(logging.StreamHandler):
|
||||
self.db = db
|
||||
self.manager = manager
|
||||
self.buffer_size = buffer_size
|
||||
self.buffer = []
|
||||
self.buffer: list[str] = []
|
||||
self._lock = Lock()
|
||||
|
||||
# Set a format that includes timestamp and level
|
||||
@@ -278,14 +286,6 @@ class WorkerManager:
|
||||
self._stdout_flush_bytes = 4096
|
||||
self._stdout_flush_interval = 0.75
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close the database connection."""
|
||||
if self.db:
|
||||
try:
|
||||
with self._db_lock:
|
||||
self.db.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
"""Context manager entry."""
|
||||
@@ -478,7 +478,7 @@ class WorkerManager:
|
||||
True if update was successful
|
||||
"""
|
||||
try:
|
||||
kwargs = {}
|
||||
kwargs: dict[str, Any] = {}
|
||||
if progress > 0:
|
||||
kwargs["progress"] = progress
|
||||
if current_step:
|
||||
|
||||
Reference in New Issue
Block a user