44import os
55import time
66from typing import Any , Dict , List , BinaryIO
7+ from tqdm import tqdm # type: ignore
78
89import backoff
910import ndjson
@@ -25,6 +26,7 @@ class AnnotationImport(DbObject):
2526 input_file_url = Field .String ("input_file_url" )
2627 error_file_url = Field .String ("error_file_url" )
2728 status_file_url = Field .String ("status_file_url" )
29+ progress = Field .String ("progress" )
2830
2931 created_by = Relationship .ToOne ("User" , False , "created_by" )
3032
@@ -76,18 +78,28 @@ def statuses(self) -> List[Dict[str, Any]]:
7678 self .wait_until_done ()
7779 return self ._fetch_remote_ndjson (self .status_file_url )
7880
79- def wait_until_done (self , sleep_time_seconds : int = 10 ) -> None :
81+ def wait_until_done (self ,
82+ sleep_time_seconds : int = 10 ,
83+ show_progress : bool = False ) -> None :
8084 """Blocks import job until certain conditions are met.
8185 Blocks until the AnnotationImport.state changes either to
8286 `AnnotationImportState.FINISHED` or `AnnotationImportState.FAILED`,
8387 periodically refreshing object's state.
8488 Args:
85- sleep_time_seconds (str): a time to block between subsequent API calls
89+ sleep_time_seconds (int): a time to block between subsequent API calls
90+ show_progress (bool): should show progress bar
8691 """
92+ pbar = tqdm (total = 100 ) if show_progress else None
8793 while self .state .value == AnnotationImportState .RUNNING .value :
8894 logger .info (f"Sleeping for { sleep_time_seconds } seconds..." )
8995 time .sleep (sleep_time_seconds )
9096 self .__backoff_refresh ()
97+ if self .progress and pbar :
98+ pbar .update (self .progress )
99+
100+ if pbar :
101+ pbar .update (100 )
102+ pbar .close ()
91103
92104 @backoff .on_exception (
93105 backoff .expo ,
0 commit comments