Skip to content

Commit

Permalink
Merge pull request #1002 from roboflow/feature/adjust-batch-processin…
Browse files Browse the repository at this point in the history
…g-cli

Adjust Roboflow Batch CLI to display task progress
  • Loading branch information
PawelPeczek-Roboflow authored Feb 6, 2025
2 parents d1ef946 + b6d0af4 commit d9ac358
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import random
import string
import time
from collections import Counter
from datetime import datetime, timedelta, timezone
from typing import List, Optional, Union
Expand All @@ -11,6 +12,15 @@
from rich.console import Console
from rich.json import JSON
from rich.panel import Panel
from rich.progress import (
BarColumn,
Progress,
ProgressSample,
Task,
TaskID,
TaskProgressColumn,
TextColumn,
)
from rich.table import Table
from rich.text import Text

Expand Down Expand Up @@ -200,6 +210,13 @@ def display_batch_job_details(job_id: str, api_key: Optional[str]) -> None:
most_recent_task_update_time = stage.start_timestamp
if job_tasks:
most_recent_task_update_time = max([t.event_timestamp for t in job_tasks])
single_task_progress = 1 / stage.tasks_number
accumulated_progress = 0.0
for task in job_tasks:
if task.is_terminal:
accumulated_progress += single_task_progress
else:
accumulated_progress += task.progress * single_task_progress
succeeded_tasks = [t for t in job_tasks if "success" in t.status_type.lower()]
failed_tasks = [t for t in job_tasks if "error" in t.status_type.lower()]
failed_tasks_statuses = Counter([t.status_name for t in failed_tasks])
Expand Down Expand Up @@ -259,6 +276,16 @@ def display_batch_job_details(job_id: str, api_key: Optional[str]) -> None:
f"⏳️: {tasks_waiting_for_processing}, 🏃: {running_tasks}, 🏁: {terminated_tasks} "
f"(out of {expected_tasks})",
)
progress = Progress(BarColumn(), TaskProgressColumn())
completed = round(accumulated_progress * 100, 2)
_ = progress.add_task(
description="Stage Progress",
total=100.0,
start=completed > 0,
completed=completed,
)

details_table.add_row("Progress", progress.get_renderable())
details_table.add_row(
"Completed Tasks Status",
f"✅: {len(succeeded_tasks)}, ❌: {len(failed_tasks)}",
Expand Down
2 changes: 1 addition & 1 deletion inference_cli/lib/roboflow_cloud/batch_processing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def list_jobs(
Optional[int],
typer.Option(
"--max-pages",
"-m",
"-p",
help="Number of pagination pages with batch jobs to display",
),
] = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TaskStatus(BaseModel):
status_name: str = Field(alias="statusName")
status_type: str = Field(alias="statusType")
is_terminal: bool = Field(alias="isTerminal")
progress: float = Field(default=0.0)
event_timestamp: datetime = Field(alias="eventTimestamp")


Expand Down

0 comments on commit d9ac358

Please sign in to comment.