Skip to content

Commit a6cebf1

Browse files
committed
factorize a bit in helper method
1 parent 56c15c8 commit a6cebf1

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

dataikuapi/dss/future.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ def __init__(self, client, job_id, state=None):
1010
self.state = state
1111
self.state_is_peek = True
1212

13+
@classmethod
14+
def get_result_wait_if_needed(cls, client, ret):
15+
if 'jobId' in ret:
16+
future = DSSFuture(client, ret["jobId"], ret)
17+
future.wait_for_result()
18+
return future.get_result()
19+
else:
20+
return ret['result']
21+
1322
def abort(self):
1423
"""
1524
Abort the future

dataikuapi/dss/project.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,7 @@ def list_sql_tables(self, connection_name, schema_name=None):
891891

892892
def to_schema_table_pair(x):
893893
return {"schema":x.get("schema", None), "table":x["table"]}
894-
if 'jobId' in ret:
895-
future = self.client.get_future(ret["jobId"])
896-
future.wait_for_result()
897-
return [to_schema_table_pair(x) for x in future.get_result()]
898-
else:
899-
return [to_schema_table_pair(x) for x in ret['result']]
894+
return [to_schema_table_pair(x) for x in DSSFuture.get_result_wait_if_needed(self.client, ret)['tables']]
900895

901896
def list_hive_tables(self, hive_database):
902897
"""
@@ -910,12 +905,7 @@ def list_hive_tables(self, hive_database):
910905

911906
def to_schema_table_pair(x):
912907
return {"schema":x.get("databaseName", None), "table":x["table"]}
913-
if 'jobId' in ret:
914-
future = self.client.get_future(ret["jobId"])
915-
future.wait_for_result()
916-
return [to_schema_table_pair(x) for x in future.get_result()['tables']]
917-
else:
918-
return [to_schema_table_pair(x) for x in ret['result']['tables']]
908+
return [to_schema_table_pair(x) for x in DSSFuture.get_result_wait_if_needed(self.client, ret)['tables']]
919909

920910
class TablesImportDefinition(object):
921911
"""

0 commit comments

Comments
 (0)