From e921614a02711c8f7a350ff8ee93872bc3ca478b Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Wed, 6 Mar 2024 10:36:01 +0100 Subject: [PATCH 1/3] Accept sleep_max in ApiClient --- cads_api_client/api_client.py | 6 +++++- cads_api_client/processing.py | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cads_api_client/api_client.py b/cads_api_client/api_client.py index c15fd96..5a9257f 100644 --- a/cads_api_client/api_client.py +++ b/cads_api_client/api_client.py @@ -12,6 +12,7 @@ class ApiClient: key: Optional[str] = None url: Optional[str] = None session: requests.Session = attrs.field(factory=requests.Session) + sleep_max: int = 120 def get_url(self) -> str: return self.url or config.get_config("url") @@ -34,7 +35,10 @@ def catalogue_api(self) -> catalogue.Catalogue: @functools.cached_property def retrieve_api(self) -> processing.Processing: return processing.Processing( - f"{self.get_url()}/retrieve", headers=self._headers(), session=self.session + f"{self.get_url()}/retrieve", + headers=self._headers(), + session=self.session, + sleep_max=self.sleep_max, ) @functools.cached_property diff --git a/cads_api_client/processing.py b/cads_api_client/processing.py index 9578dc4..3ffc4d1 100644 --- a/cads_api_client/processing.py +++ b/cads_api_client/processing.py @@ -255,12 +255,12 @@ def download( @attrs.define class StatusInfo(ApiResponse): - def make_remote(self) -> Remote: + def make_remote(self, **kwargs: Any) -> Remote: if self.response.request.method == "POST": url = self.get_link_href(rel="monitor") else: url = self.get_link_href(rel="self") - return Remote(url, headers=self.headers, session=self.session) + return Remote(url, headers=self.headers, session=self.session, **kwargs) @attrs.define @@ -332,6 +332,7 @@ def download( class Processing: supported_api_version = "v1" + sleep_max: int = 120 def __init__( self, @@ -402,7 +403,9 @@ def submit( status_info = self.process_execute( collection_id, request, retry_options=retry_options ) - return status_info.make_remote() + return status_info.make_remote( + retry_options=retry_options, sleep_max=self.sleep_max + ) def submit_and_wait_on_result( self, collection_id: str, retry_options: Dict[str, Any] = {}, **request: Any @@ -413,10 +416,14 @@ def submit_and_wait_on_result( def make_remote(self, job_id: str) -> Remote: url = f"{self.url}/jobs/{job_id}" - return Remote(url, headers=self.headers, session=self.session) + return Remote( + url, headers=self.headers, session=self.session, sleep_max=self.sleep_max + ) def download_result( self, job_id: str, target: Optional[str], retry_options: Dict[str, Any] ) -> str: # NOTE: the remote waits for the result to be available - return self.make_remote(job_id).download(target, retry_options=retry_options) + return self.make_remote(job_id, sleep_max=self.sleep_max).download( + target, retry_options=retry_options + ) From 9723b93f4a445f3c88a50672bbb9ad4075a24c01 Mon Sep 17 00:00:00 2001 From: Alessandro Amici Date: Wed, 6 Mar 2024 10:40:33 +0100 Subject: [PATCH 2/3] Fix a few bugs --- cads_api_client/processing.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cads_api_client/processing.py b/cads_api_client/processing.py index 3ffc4d1..cddfa34 100644 --- a/cads_api_client/processing.py +++ b/cads_api_client/processing.py @@ -332,7 +332,6 @@ def download( class Processing: supported_api_version = "v1" - sleep_max: int = 120 def __init__( self, @@ -340,12 +339,14 @@ def __init__( force_exact_url: bool = False, headers: Dict[str, Any] = {}, session: requests.Session = requests.api, # type: ignore + sleep_max: int = 120, ) -> None: if not force_exact_url: url = f"{url}/{self.supported_api_version}" self.url = url self.headers = headers self.session = session + self.sleep_max = sleep_max def processes(self, params: Dict[str, Any] = {}) -> ProcessList: url = f"{self.url}/processes" @@ -424,6 +425,4 @@ def download_result( self, job_id: str, target: Optional[str], retry_options: Dict[str, Any] ) -> str: # NOTE: the remote waits for the result to be available - return self.make_remote(job_id, sleep_max=self.sleep_max).download( - target, retry_options=retry_options - ) + return self.make_remote(job_id).download(target, retry_options=retry_options) From 102b88045586be8ec790c8537d016f4410bb7364 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 6 Mar 2024 13:20:57 +0100 Subject: [PATCH 3/3] bug fix --- cads_api_client/processing.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cads_api_client/processing.py b/cads_api_client/processing.py index cddfa34..1545d77 100644 --- a/cads_api_client/processing.py +++ b/cads_api_client/processing.py @@ -404,9 +404,7 @@ def submit( status_info = self.process_execute( collection_id, request, retry_options=retry_options ) - return status_info.make_remote( - retry_options=retry_options, sleep_max=self.sleep_max - ) + return status_info.make_remote(sleep_max=self.sleep_max) def submit_and_wait_on_result( self, collection_id: str, retry_options: Dict[str, Any] = {}, **request: Any