1
1
"""
2
2
Implementation of `Sentinel Hub Process API interface <https://docs.sentinel-hub.com/api/latest/api/process/>`__.
3
3
"""
4
- from typing import Any , Dict , List , Optional , Tuple , Union
4
+ from typing import Any , Dict , Iterable , List , Optional , Tuple , Union
5
5
6
+ import requests
7
+
8
+ from sentinelhub .exceptions import DownloadFailedException
9
+
10
+ from ..config import SHConfig
6
11
from ..constants import MimeType
7
12
from ..download import SentinelHubDownloadClient
8
13
from ..geometry import BBox , Geometry
@@ -29,7 +34,7 @@ def __init__(
29
34
geometry : Optional [Geometry ] = None ,
30
35
size : Optional [Tuple [int , int ]] = None ,
31
36
resolution : Optional [Tuple [float , float ]] = None ,
32
- ** kwargs : Any
37
+ ** kwargs : Any ,
33
38
):
34
39
"""
35
40
For details of certain parameters check the
@@ -163,7 +168,7 @@ def __init__(
163
168
geometry : Optional [Geometry ] = None ,
164
169
size : Optional [Tuple [int , int ]] = None ,
165
170
resolution : Optional [Tuple [float , float ]] = None ,
166
- ** kwargs : Any
171
+ ** kwargs : Any ,
167
172
):
168
173
"""
169
174
For details of certain parameters check the
@@ -283,3 +288,29 @@ def output(
283
288
_update_other_args (request_output , other_args )
284
289
285
290
return request_output
291
+
292
+
293
+ def get_async_running_status (ids : Iterable [str ], config : Optional [SHConfig ] = None ) -> Dict [str , bool ]:
294
+ """Returns a mapping that describes which requests are running.
295
+
296
+ :param ids: A collection of async request IDs.
297
+ :param config: A custom instance of config class to override parameters from the saved configuration.
298
+ :return: A mapping that specifies whether a process is running for each of the IDs.
299
+ """
300
+ config = config or SHConfig ()
301
+ client = SentinelHubDownloadClient (config = config )
302
+ result = {}
303
+ for request_id in ids :
304
+ try :
305
+ client .get_json_dict (f"{ config .sh_base_url } /api/v1/async/process/{ request_id } " , use_session = True )
306
+ # A successful request means it's running
307
+ result [request_id ] = True
308
+ except DownloadFailedException as exception :
309
+ code_not_found = requests .status_codes .codes .NOT_FOUND
310
+ # A 404 means it's not running
311
+ if exception .request_exception and exception .request_exception .response .status_code == code_not_found :
312
+ result [request_id ] = False
313
+ else :
314
+ raise exception from exception
315
+
316
+ return result
0 commit comments