Skip to content

Commit 700a287

Browse files
Rename progress bars to progress indicators
1 parent e96f916 commit 700a287

15 files changed

Lines changed: 462 additions & 388 deletions

File tree

tilebox-workflows/tests/runner/test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from tilebox.workflows import ExecutionContext, Task
1010
from tilebox.workflows.cache import InMemoryCache, JobCache
1111
from tilebox.workflows.client import Client
12-
from tilebox.workflows.data import JobState, ProgressBar, RunnerContext
12+
from tilebox.workflows.data import JobState, ProgressIndicator, RunnerContext
1313
from tilebox.workflows.runner.task_runner import TaskRunner
1414

1515

@@ -147,7 +147,7 @@ def test_runner_with_workflow_tracking_progress() -> None:
147147
runner.run_all()
148148
job = job_client.find(job) # load current job state
149149
assert job.state == JobState.COMPLETED
150-
assert job.progress_bars == [ProgressBar("test", 4, 4)]
150+
assert job.progress == [ProgressIndicator("test", 4, 4)]
151151

152152

153153
def replay_client(replay_file: str, assert_request_matches: bool = True) -> Client:

tilebox-workflows/tests/tasks_data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Idling,
3232
Job,
3333
JobState,
34-
ProgressBar,
34+
ProgressIndicator,
3535
StorageEventTrigger,
3636
StorageLocation,
3737
StorageType,
@@ -59,12 +59,12 @@ def clusters(draw: DrawFn) -> Cluster:
5959

6060

6161
@composite
62-
def progress_bars(draw: DrawFn) -> ProgressBar:
63-
"""A hypothesis strategy for generating random progress_bars"""
62+
def progress_indicators(draw: DrawFn) -> ProgressIndicator:
63+
"""A hypothesis strategy for generating random progress indicators"""
6464
label = draw(one_of(alphanumerical_text(), none()))
6565
total = draw(integers(min_value=50, max_value=1000))
6666
done = draw(integers(min_value=0, max_value=total))
67-
return ProgressBar(label, total, done)
67+
return ProgressIndicator(label, total, done)
6868

6969

7070
@composite
@@ -134,7 +134,7 @@ def jobs(draw: DrawFn, canceled: bool | None = None) -> Job:
134134
if canceled is None:
135135
canceled = draw(booleans())
136136

137-
progress = draw(lists(progress_bars(), min_size=0, max_size=3))
137+
progress = draw(lists(progress_indicators(), min_size=0, max_size=3))
138138

139139
return Job(
140140
job_id,
@@ -167,7 +167,7 @@ def computed_tasks(draw: DrawFn) -> ComputedTask:
167167
task_id = draw(uuids(version=4))
168168
display = draw(alphanumerical_text())
169169
subtasks: list[TaskSubmission] = draw(lists(task_submissions(), min_size=1, max_size=10))
170-
progress_updates = draw(lists(progress_bars(), min_size=0, max_size=3))
170+
progress_updates = draw(lists(progress_indicators(), min_size=0, max_size=3))
171171

172172
return ComputedTask(task_id, display, subtasks, progress_updates)
173173

tilebox-workflows/tests/test_data.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
computed_tasks,
77
idling_responses,
88
jobs,
9-
progress_bars,
9+
progress_indicators,
1010
storage_locations,
1111
task_identifiers,
1212
task_leases,
@@ -19,7 +19,7 @@
1919
ComputedTask,
2020
Idling,
2121
Job,
22-
ProgressBar,
22+
ProgressIndicator,
2323
StorageLocation,
2424
Task,
2525
TaskIdentifier,
@@ -33,9 +33,9 @@ def test_task_identifiers_to_message_and_back(task_id: TaskIdentifier) -> None:
3333
assert TaskIdentifier.from_message(task_id.to_message()) == task_id
3434

3535

36-
@given(progress_bars())
37-
def test_progress_bars_to_message_and_back(progress_bar: ProgressBar) -> None:
38-
assert ProgressBar.from_message(progress_bar.to_message()) == progress_bar
36+
@given(progress_indicators())
37+
def test_progress_indicators_to_message_and_back(progress_indicator: ProgressIndicator) -> None:
38+
assert ProgressIndicator.from_message(progress_indicator.to_message()) == progress_indicator
3939

4040

4141
@given(tasks())

tilebox-workflows/tilebox/workflows/data.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ def to_message(self) -> core_pb2.TaskLease:
108108

109109

110110
@dataclass(order=True)
111-
class ProgressBar:
111+
class ProgressIndicator:
112112
label: str | None
113113
total: int
114114
done: int
115115

116116
@classmethod
117-
def from_message(cls, progress_bar: core_pb2.ProgressBar) -> "ProgressBar":
118-
"""Convert a ProgressBar protobuf message to a ProgressBar object."""
119-
return cls(label=progress_bar.label or None, total=progress_bar.total, done=progress_bar.done)
117+
def from_message(cls, progress_indicator: core_pb2.Progress) -> "ProgressIndicator":
118+
"""Convert a ProgressIndicator protobuf message to a ProgressIndicator object."""
119+
return cls(label=progress_indicator.label or None, total=progress_indicator.total, done=progress_indicator.done)
120120

121-
def to_message(self) -> core_pb2.ProgressBar:
122-
"""Convert a ProgressBar object to a ProgressBar protobuf message."""
123-
return core_pb2.ProgressBar(label=self.label, total=self.total, done=self.done)
121+
def to_message(self) -> core_pb2.Progress:
122+
"""Convert a ProgressIndicator object to a ProgressIndicator protobuf message."""
123+
return core_pb2.Progress(label=self.label, total=self.total, done=self.done)
124124

125125

126126
@dataclass(order=True)
@@ -204,7 +204,7 @@ class Job:
204204
submitted_at: datetime
205205
started_at: datetime | None
206206
canceled: bool
207-
progress_bars: list[ProgressBar]
207+
progress: list[ProgressIndicator]
208208

209209
@classmethod
210210
def from_message(cls, job: core_pb2.Job) -> "Job": # lets use typing.Self once we require python >= 3.11
@@ -217,7 +217,7 @@ def from_message(cls, job: core_pb2.Job) -> "Job": # lets use typing.Self once
217217
submitted_at=timestamp_to_datetime(job.submitted_at),
218218
started_at=timestamp_to_datetime(job.started_at) if job.HasField("started_at") else None,
219219
canceled=job.canceled,
220-
progress_bars=[ProgressBar.from_message(progress_bar) for progress_bar in job.progress_bars],
220+
progress=[ProgressIndicator.from_message(progress) for progress in job.progress],
221221
)
222222

223223
def to_message(self) -> core_pb2.Job:
@@ -230,7 +230,7 @@ def to_message(self) -> core_pb2.Job:
230230
submitted_at=datetime_to_timestamp(self.submitted_at),
231231
started_at=datetime_to_timestamp(self.started_at) if self.started_at else None,
232232
canceled=self.canceled,
233-
progress_bars=[progress_bar.to_message() for progress_bar in self.progress_bars],
233+
progress=[progress.to_message() for progress in self.progress],
234234
)
235235

236236

@@ -303,7 +303,7 @@ class ComputedTask:
303303
id: UUID
304304
display: str | None
305305
sub_tasks: list[TaskSubmission]
306-
progress_updates: list[ProgressBar]
306+
progress_updates: list[ProgressIndicator]
307307

308308
@classmethod
309309
def from_message(cls, computed_task: task_pb2.ComputedTask) -> "ComputedTask":
@@ -312,7 +312,7 @@ def from_message(cls, computed_task: task_pb2.ComputedTask) -> "ComputedTask":
312312
id=uuid_message_to_uuid(computed_task.id),
313313
display=computed_task.display,
314314
sub_tasks=[TaskSubmission.from_message(sub_task) for sub_task in computed_task.sub_tasks],
315-
progress_updates=[ProgressBar.from_message(progress) for progress in computed_task.progress_updates],
315+
progress_updates=[ProgressIndicator.from_message(progress) for progress in computed_task.progress_updates],
316316
)
317317

318318
def to_message(self) -> task_pb2.ComputedTask:

tilebox-workflows/tilebox/workflows/runner/task_runner.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from _tilebox.grpc.error import InternalServerError
2929
from tilebox.datasets.sync.dataset import DatasetClient
3030
from tilebox.workflows.cache import JobCache
31-
from tilebox.workflows.data import ComputedTask, Idling, NextTaskToRun, ProgressBar, Task, TaskLease
31+
from tilebox.workflows.data import ComputedTask, Idling, NextTaskToRun, ProgressIndicator, Task, TaskLease
3232
from tilebox.workflows.interceptors import Interceptor, InterceptorType
3333
from tilebox.workflows.observability.logging import get_logger
3434
from tilebox.workflows.observability.tracing import WorkflowTracer
@@ -56,7 +56,7 @@
5656
_FALLBACK_JITTER_INTERVAL = timedelta(seconds=5)
5757

5858
# Maximum number of progress bars per task, mirroring the limit on the server side
59-
_MAX_TASK_PROGRESS_BARS = 1000
59+
_MAX_TASK_PROGRESS_INDICATORS = 1000
6060

6161
WrappedFnReturnT = TypeVar("WrappedFnReturnT")
6262

@@ -217,7 +217,7 @@ def _external_interrupt_handler(self, signum: int, frame: FrameType | None) -> N
217217
if self._task is not None:
218218
progress = []
219219
if self._context is not None:
220-
progress = _mutable_progress_bars_to_progress_updates(self._context._progress_bars) # noqa: SLF001
220+
progress = _finalize_mutable_progress_trackers(self._context._progress_indicators) # noqa: SLF001
221221
self._service.task_failed(
222222
self._task,
223223
RunnerShutdown("Task was interrupted"),
@@ -431,7 +431,7 @@ def _execute(self, task: Task, shutdown_context: _GracefulShutdown) -> Task | Id
431431

432432
task_failed_retry = _retry_backoff(self._service.task_failed, stop=shutdown_context.stop_if_shutting_down())
433433
cancel_job = True
434-
progress_updates = _mutable_progress_bars_to_progress_updates(context._progress_bars) # noqa: SLF001
434+
progress_updates = _finalize_mutable_progress_trackers(context._progress_indicators) # noqa: SLF001
435435
task_failed_retry(task, e, cancel_job, progress_updates)
436436

437437
return None
@@ -493,7 +493,7 @@ def _try_execute(
493493
task.to_submission(self.tasks_to_run.cluster_slug)
494494
for task in context._sub_tasks # noqa: SLF001
495495
],
496-
progress_updates=_mutable_progress_bars_to_progress_updates(context._progress_bars), # noqa: SLF001
496+
progress_updates=_finalize_mutable_progress_trackers(context._progress_indicators), # noqa: SLF001
497497
)
498498

499499
next_task_retry = _retry_backoff(self._service.next_task, stop=shutdown_context.stop_if_shutting_down())
@@ -513,7 +513,7 @@ def __init__(self, runner: TaskRunner, task: Task, job_cache: JobCache) -> None:
513513
self.current_task = task
514514
self.job_cache = job_cache
515515
self._sub_tasks: list[FutureTask] = []
516-
self._progress_bars: dict[str | None, ProgressUpdate] = {}
516+
self._progress_indicators: dict[str | None, ProgressUpdate] = {}
517517

518518
def submit_subtask(
519519
self,
@@ -548,20 +548,20 @@ def submit_batch(
548548
)
549549
return self.submit_subtasks(tasks, cluster, max_retries)
550550

551-
def progress(self, label: str | None) -> ProgressUpdate:
551+
def progress(self, label: str | None = None) -> ProgressUpdate:
552552
if label == "":
553553
label = None
554554

555-
if label in self._progress_bars:
556-
return self._progress_bars[label]
555+
if label in self._progress_indicators:
556+
return self._progress_indicators[label]
557557

558558
# this is our server side limit to prevent mistakes / abuse, so let's not allow to go beyond that already
559559
# client side
560-
if len(self._progress_bars) > _MAX_TASK_PROGRESS_BARS:
561-
raise ValueError(f"Cannot create more than {_MAX_TASK_PROGRESS_BARS} progress bars per task.")
560+
if len(self._progress_indicators) > _MAX_TASK_PROGRESS_INDICATORS:
561+
raise ValueError(f"Cannot create more than {_MAX_TASK_PROGRESS_INDICATORS} progress indicators per task.")
562562

563563
progress_bar = ProgressUpdate(label)
564-
self._progress_bars[label] = progress_bar
564+
self._progress_indicators[label] = progress_bar
565565
return progress_bar
566566

567567
@property
@@ -577,8 +577,10 @@ def _dataset(self, dataset_id: str) -> DatasetClient:
577577
return client.dataset(dataset_id)
578578

579579

580-
def _mutable_progress_bars_to_progress_updates(progress_bars: dict[str | None, ProgressUpdate]) -> list[ProgressBar]:
581-
return [ProgressBar(label, bar._total, bar._done) for label, bar in progress_bars.items()] # noqa: SLF001
580+
def _finalize_mutable_progress_trackers(
581+
progress_bars: dict[str | None, ProgressUpdate],
582+
) -> list[ProgressIndicator]:
583+
return [ProgressIndicator(label, bar._total, bar._done) for label, bar in progress_bars.items()] # noqa: SLF001
582584

583585

584586
def _execute(task: TaskInstance, context: ExecutionContext, additional_interceptors: list[Interceptor]) -> None:

tilebox-workflows/tilebox/workflows/runner/task_service.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
ComputedTask,
99
Idling,
1010
NextTaskToRun,
11-
ProgressBar,
11+
ProgressIndicator,
1212
Task,
1313
TaskLease,
1414
uuid_to_uuid_message,
@@ -48,7 +48,9 @@ def next_task(self, task_to_run: NextTaskToRun | None, computed_task: ComputedTa
4848
return Idling.from_message(response.idling)
4949
return None
5050

51-
def task_failed(self, task: Task, error: Exception, cancel_job: bool, progress_updates: list[ProgressBar]) -> None:
51+
def task_failed(
52+
self, task: Task, error: Exception, cancel_job: bool, progress_updates: list[ProgressIndicator]
53+
) -> None:
5254
# job ouptut is limited to 1KB, so truncate the error message if necessary
5355
error_message = repr(error)[: (1024 - len(task.display or "None") - 1)]
5456
display = f"{task.display}" if error_message == "" else f"{task.display}\n{error_message}"

tilebox-workflows/tilebox/workflows/task.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ def __init__(self, label: str | None) -> None:
254254
self._done = 0
255255

256256
def add(self, count: int) -> None:
257-
"""Add a given amount of total work to be done to the progress bar.
257+
"""Add a given amount of total work to be done to the progress indicator.
258258
259259
Args:
260-
count: The amount of work to add to the progress bar.
260+
count: The amount of work to add to the progress indicator.
261261
"""
262262
self._total += count
263263

@@ -307,8 +307,8 @@ def runner_context(self) -> RunnerContext:
307307
"""Get the runner context for the task runner executing the task."""
308308

309309
@abstractmethod
310-
def progress(self, label: str | None) -> ProgressUpdate:
311-
"""Get a progress bar instance for tracking job progress."""
310+
def progress(self, label: str | None = None) -> ProgressUpdate:
311+
"""Get a progress indicator instance for tracking job progress."""
312312

313313

314314
def serialize_task(task: Task) -> bytes:

0 commit comments

Comments
 (0)