Skip to content

Commit

Permalink
[#65] re-fetching resource/aggregation asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdash committed Apr 27, 2024
1 parent 9da2a23 commit 908b561
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions hsclient/hydroshare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import getpass
import multiprocessing
import os
import pathlib
import pickle
Expand Down Expand Up @@ -258,6 +259,21 @@ def _download(self, save_path: str = "", unzip_to: str = None) -> str:
return unzip_to
return downloaded_zip

def _reset(self):
self._retrieved_map = None
self._retrieved_metadata = None
self._parsed_files = None
self._parsed_aggregations = None
self._parsed_checksums = None
self._main_file_path = None

def _refetch(self):
_ = self._map
_ = self._metadata
_ = self._checksums
_ = self._files
_ = self._aggregations

@property
def metadata_file(self):
"""The path to the metadata file"""
Expand Down Expand Up @@ -367,13 +383,11 @@ def refresh(self) -> None:
only retrieve those files again after another call to access them is made. This will be later updated to be
eager and retrieve the files asynchronously.
"""
# TODO, refresh should destroy the aggregation objects and async fetch everything.
self._retrieved_map = None
self._retrieved_metadata = None
self._parsed_files = None
self._parsed_aggregations = None
self._parsed_checksums = None
self._main_file_path = None

self._reset()
# async re-fetch aggregation/resource map and metadata files form HydroShare
with multiprocessing.Pool() as pool:
pool.apply_async(self._refetch)

def delete(self) -> None:
"""Deletes this aggregation from HydroShare"""
Expand Down

0 comments on commit 908b561

Please sign in to comment.