Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into legacy-retry-options
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 committed Mar 6, 2024
2 parents 4ce4e78 + 3a5e33f commit 2e3f8ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion cads_api_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions cads_api_client/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -339,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"
Expand Down Expand Up @@ -402,7 +404,7 @@ def submit(
status_info = self.process_execute(
collection_id, request, retry_options=retry_options
)
return status_info.make_remote()
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
Expand All @@ -413,7 +415,9 @@ 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]
Expand Down

0 comments on commit 2e3f8ad

Please sign in to comment.