|
4 | 4 | import os |
5 | 5 | import time |
6 | 6 | from typing import Any, Dict, List, BinaryIO |
| 7 | +from tqdm import tqdm |
7 | 8 |
|
8 | 9 | import backoff |
9 | 10 | import ndjson |
@@ -77,18 +78,24 @@ def statuses(self) -> List[Dict[str, Any]]: |
77 | 78 | self.wait_until_done() |
78 | 79 | return self._fetch_remote_ndjson(self.status_file_url) |
79 | 80 |
|
80 | | - def wait_until_done(self, sleep_time_seconds: int = 10) -> None: |
| 81 | + def wait_until_done(self, sleep_time_seconds: int = 10, show_progress: bool = True) -> None: |
81 | 82 | """Blocks import job until certain conditions are met. |
82 | 83 | Blocks until the AnnotationImport.state changes either to |
83 | 84 | `AnnotationImportState.FINISHED` or `AnnotationImportState.FAILED`, |
84 | 85 | periodically refreshing object's state. |
85 | 86 | Args: |
86 | | - sleep_time_seconds (str): a time to block between subsequent API calls |
87 | | - """ |
88 | | - while self.state.value == AnnotationImportState.RUNNING.value: |
89 | | - logger.info(f"Sleeping for {sleep_time_seconds} seconds...") |
90 | | - time.sleep(sleep_time_seconds) |
91 | | - self.__backoff_refresh() |
| 87 | + sleep_time_seconds (int): a time to block between subsequent API calls |
| 88 | + show_progress (bool): should show progress bar |
| 89 | + """ |
| 90 | + with tqdm(total=100) as pbar: |
| 91 | + while self.state.value == AnnotationImportState.RUNNING.value: |
| 92 | + logger.info(f"Sleeping for {sleep_time_seconds} seconds...") |
| 93 | + time.sleep(sleep_time_seconds) |
| 94 | + self.__backoff_refresh() |
| 95 | + if self.progress: |
| 96 | + pbar.update(self.progress) |
| 97 | + |
| 98 | + pbar.update(100) |
92 | 99 |
|
93 | 100 | @backoff.on_exception( |
94 | 101 | backoff.expo, |
|
0 commit comments