sws-api-client 0.0.6.dev0__tar.gz → 0.0.8.dev0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sws_api_client-0.0.6.dev0/sws_api_client.egg-info → sws_api_client-0.0.8.dev0}/PKG-INFO +1 -1
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/setup.py +1 -1
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client/tasks.py +41 -3
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0/sws_api_client.egg-info}/PKG-INFO +1 -1
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/LICENSE +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/README.md +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/setup.cfg +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client/__init__.py +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client/datasets.py +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client/discover.py +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client/sws_api_client.py +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client/tags.py +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client.egg-info/SOURCES.txt +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client.egg-info/dependency_links.txt +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client.egg-info/requires.txt +0 -0
- {sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sws_api_client
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8.dev0
|
|
4
4
|
Summary: A Python client to easily interact with the FAO SWS REST APIs
|
|
5
5
|
Home-page: https://bitbucket.org/cioapps/sws-it-python-api-client/src/main/
|
|
6
6
|
Author: Mansillo, Daniele (CSI)
|
|
@@ -47,6 +47,10 @@ class TaskResponse:
|
|
|
47
47
|
task_id: str
|
|
48
48
|
info: TaskInfo
|
|
49
49
|
|
|
50
|
+
@dataclass
|
|
51
|
+
class TaskCreateResponse:
|
|
52
|
+
task_id: str
|
|
53
|
+
|
|
50
54
|
class TaskManager:
|
|
51
55
|
|
|
52
56
|
def __init__(self, sws_client: SwsApiClient, endpoint: str = 'task_manager_api') -> None:
|
|
@@ -75,7 +79,7 @@ class TaskManager:
|
|
|
75
79
|
group: Optional[str] = None,
|
|
76
80
|
parentTaskId: Optional[str] = None,
|
|
77
81
|
user:Optional[str] = None
|
|
78
|
-
) ->
|
|
82
|
+
) -> TaskCreateResponse:
|
|
79
83
|
|
|
80
84
|
path = 'task/create'
|
|
81
85
|
|
|
@@ -100,7 +104,7 @@ class TaskManager:
|
|
|
100
104
|
|
|
101
105
|
response = self.sws_client.discoverable.post(self.endpoint, path, data=data)
|
|
102
106
|
if response:
|
|
103
|
-
return self.
|
|
107
|
+
return self.get_task_create_response(response)
|
|
104
108
|
else:
|
|
105
109
|
return None
|
|
106
110
|
|
|
@@ -126,6 +130,11 @@ class TaskManager:
|
|
|
126
130
|
group=task['info'].get('group')
|
|
127
131
|
)
|
|
128
132
|
)
|
|
133
|
+
|
|
134
|
+
def get_task_create_response(self, task: Dict) -> TaskCreateResponse:
|
|
135
|
+
return TaskCreateResponse(
|
|
136
|
+
task_id=task['taskId']
|
|
137
|
+
)
|
|
129
138
|
|
|
130
139
|
|
|
131
140
|
def get_task(self, task_id: str) -> Optional[TaskResponse]:
|
|
@@ -136,6 +145,14 @@ class TaskManager:
|
|
|
136
145
|
return self.get_task_response(response)
|
|
137
146
|
else:
|
|
138
147
|
return None
|
|
148
|
+
|
|
149
|
+
def get_tasks_by_ids(self, task_ids: List[str]) -> List[TaskResponse]:
|
|
150
|
+
path = f'/task/by-ids'
|
|
151
|
+
response = self.sws_client.discoverable.post(self.endpoint, path, data={"ids":task_ids})
|
|
152
|
+
# the response is an object like this: {id, data?, error?}[]
|
|
153
|
+
# we need to convert the task object to a TaskResponse object and return a list of TaskResponse objects
|
|
154
|
+
if response:
|
|
155
|
+
return [self.get_task_response(obj.get('data')) for obj in response if obj.get('data')]
|
|
139
156
|
|
|
140
157
|
def wait_completion(self, task_id: str, poll_interval: int = 10) -> TaskResponse:
|
|
141
158
|
"""
|
|
@@ -159,4 +176,25 @@ class TaskManager:
|
|
|
159
176
|
if task_status == 'ENDED':
|
|
160
177
|
return task_response
|
|
161
178
|
|
|
162
|
-
time.sleep(poll_interval)
|
|
179
|
+
time.sleep(poll_interval)
|
|
180
|
+
|
|
181
|
+
def wait_completion_by_ids(self, task_ids: List[str], poll_interval: int = 10) -> List[TaskResponse]:
|
|
182
|
+
"""
|
|
183
|
+
Wait for a list of tasks to reach the 'ENDED' status and return the task outcomes.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
task_ids (List[str]): The IDs of the tasks.
|
|
187
|
+
poll_interval (int, optional): The interval (in seconds) between status checks. Defaults to 10.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
List[str]: The final outcomes of the tasks.
|
|
191
|
+
"""
|
|
192
|
+
completed_tasks = []
|
|
193
|
+
while True:
|
|
194
|
+
tasks_response = self.get_tasks_by_ids(task_ids)
|
|
195
|
+
completed_tasks = [task for task in tasks_response if task.info.detail_status == 'ENDED']
|
|
196
|
+
if len(completed_tasks) == len(task_ids):
|
|
197
|
+
return completed_tasks
|
|
198
|
+
|
|
199
|
+
time.sleep(poll_interval)
|
|
200
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sws_api_client
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8.dev0
|
|
4
4
|
Summary: A Python client to easily interact with the FAO SWS REST APIs
|
|
5
5
|
Home-page: https://bitbucket.org/cioapps/sws-it-python-api-client/src/main/
|
|
6
6
|
Author: Mansillo, Daniele (CSI)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client.egg-info/requires.txt
RENAMED
|
File without changes
|
{sws_api_client-0.0.6.dev0 → sws_api_client-0.0.8.dev0}/sws_api_client.egg-info/top_level.txt
RENAMED
|
File without changes
|