Skip to content

Commit 4a49fe5

Browse files
authored
PUBLICAPI-1053: progress tracker (#143)
1 parent 4ad2567 commit 4a49fe5

File tree

3 files changed

+702
-5
lines changed

3 files changed

+702
-5
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,49 @@ operation.wait_sync()
328328
print(f"New bucket ID: {operation.resource_id}")
329329
```
330330

331+
##### Progress tracker
332+
333+
Some operations expose a progress tracker with ETA, work completion, and step
334+
details. You can access it via [`Operation.progress_tracker`](https://nebius.github.io/pysdk/nebius.aio.operation.Operation.html#progress_tracker).
335+
For operations that do not provide progress details (or v1alpha1 operations),
336+
this returns `None`.
337+
338+
Example of polling with a single-line progress display:
339+
340+
```python
341+
from asyncio import sleep
342+
from datetime import datetime
343+
from nebius.base.protos.well_known import local_timezone
344+
345+
while not operation.done():
346+
await operation.update()
347+
tracker = operation.progress_tracker()
348+
parts = [f"waiting for operation {operation.id} to complete:"]
349+
350+
if tracker:
351+
work = tracker.work_fraction()
352+
if work is not None:
353+
parts.append(f"{work:.0%}")
354+
355+
desc = tracker.description()
356+
if desc:
357+
parts.append(desc)
358+
359+
started = tracker.started_at()
360+
if started is not None:
361+
elapsed = datetime.now(local_timezone) - started
362+
parts.append(f"{elapsed}")
363+
364+
eta = tracker.estimated_finished_at()
365+
if eta is not None:
366+
parts.append(f"eta {eta}")
367+
368+
print(" ".join(parts), end="\r", flush=True)
369+
await sleep(1)
370+
371+
print()
372+
```
373+
331374
##### Operations service
332375

333376
If you need to get an operation or list operations, you will need an [`OperationServiceClient`](https://nebius.github.io/pysdk/nebius.api.nebius.common.v1.OperationServiceClient.html).

0 commit comments

Comments
 (0)