@@ -64,6 +64,10 @@ def wait_till_done(self, timeout_seconds=300) -> None:
6464 check_frequency = 2 # frequency of checking, in seconds
6565 while True :
6666 if self .status != "IN_PROGRESS" :
67+ if self .status == 'FAILED' :
68+ logger .warning (
69+ "There are errors present. Please look at `task.errors` for more details"
70+ )
6771 return
6872 sleep_time_seconds = min (check_frequency , timeout_seconds )
6973 logger .debug ("Task.wait_till_done sleeping for %.2f seconds" %
@@ -94,24 +98,32 @@ def result(self) -> List[Dict[str, Any]]:
9498 return [{
9599 'id' : data_row ['id' ],
96100 'external_id' : data_row .get ('externalId' ),
97- 'row_data' : data_row ['rowData' ]
101+ 'row_data' : data_row ['rowData' ],
102+ 'global_key' : data_row .get ('globalKey' ),
98103 } for data_row in result ['createdDataRows' ]]
99104
100105 @lru_cache ()
101106 def _fetch_remote_json (self ) -> Dict [str , Any ]:
102107 """ Function for fetching and caching the result data.
103108 """
109+
110+ def download_result ():
111+ response = requests .get (self .result_url )
112+ response .raise_for_status ()
113+ return response .json ()
114+
104115 if self .name != 'JSON Import' :
105116 raise ValueError (
106117 "Task result is only supported for `JSON Import` tasks."
107118 " Download task.result_url manually to access the result for other tasks."
108119 )
109- self .wait_till_done (timeout_seconds = 600 )
110- if self .status == "IN_PROGRESS" :
111- raise ValueError (
112- "Job status still in `IN_PROGRESS`. The result is not available. Call task.wait_till_done() with a larger timeout or contact support."
113- )
114120
115- response = requests .get (self .result_url )
116- response .raise_for_status ()
117- return response .json ()
121+ if self .status != "IN_PROGRESS" :
122+ return download_result ()
123+ else :
124+ self .wait_till_done (timeout_seconds = 600 )
125+ if self .status == "IN_PROGRESS" :
126+ raise ValueError (
127+ "Job status still in `IN_PROGRESS`. The result is not available. Call task.wait_till_done() with a larger timeout or contact support."
128+ )
129+ return download_result ()
0 commit comments