Skip to content

Commit

Permalink
Merge pull request #28 from GermanoGuerrini/serverless_function
Browse files Browse the repository at this point in the history
Serverless function
  • Loading branch information
ricardo-correa authored Sep 17, 2024
2 parents 1caf9a5 + 774698e commit a1ed6f4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

Version 2.18
------------
* Download URL computation has its own method

Version 2.17
-----------
* Added Conda-Forge repository
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
copyright = "2023, ECMWF"
author = "ECMWF"

release = "2.17"
version = "2.17"
release = "2.18"
version = "2.18"

# -- General configuration

Expand Down
31 changes: 25 additions & 6 deletions hda/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,38 @@ def __getitem__(self, index):
def _download(self, result, download_dir: str = "."):
logger.debug(result)
self.client.accept_tac(self.dataset)
download_id = self._get_download_id(result)
self.stream(
download_id,
result["properties"]["size"],
download_dir,
)

def _get_download_id(self, result):
query = {
"dataset_id": self.dataset,
"product_id": result["id"],
"location": result["properties"]["location"],
}
download_id = DataOrderRequest(self.client).run(query)
return DataOrderRequest(self.client).run(query)

self.stream(
download_id,
result["properties"]["size"],
download_dir,
)
def get_download_urls(self, limit: int = None):
"""Utility function to return the list of final download URLs.
Useful in the context of the Serverless Functions service.
If the list of results is long, it might take a long time.
In that case, either subset the results or set a value for `limit`.
"""

def build_url(result):
download_id = self._get_download_id(result)
return self.client.full_url(*[f"dataaccess/download/{download_id}"])

if limit is not None:
results = self.results[:limit]
else:
results = self.results

return [build_url(r) for r in results]

def download(self, download_dir: str = "."):
"""Downloads the results into the given download directory.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def read(fname):
return io.open(file_path, encoding="utf-8").read()


version = "2.17"
version = "2.18"

setuptools.setup(
name="hda",
Expand Down

0 comments on commit a1ed6f4

Please sign in to comment.