Skip to content

Commit

Permalink
[#65] refreshing resource/aggregation as a background task using thre…
Browse files Browse the repository at this point in the history
…ading
  • Loading branch information
pkdash committed May 21, 2024
1 parent 38d979d commit 78b1242
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions hsclient/hydroshare.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import getpass
import multiprocessing
import threading
import os
import pathlib
import pickle
Expand Down Expand Up @@ -268,11 +268,10 @@ def _reset(self):
self._main_file_path = None

def _refetch(self):
# not refreshing the checksums here - they will be refreshed when needed
_ = self._map
_ = self._metadata
_ = self._checksums
_ = self._files
_ = self._aggregations

@property
def metadata_file(self) -> str:
Expand Down Expand Up @@ -378,15 +377,12 @@ def aggregation(self, **kwargs) -> Union[BaseMetadata, None]:

def refresh(self) -> None:
"""
Forces the retrieval of the resource map and metadata files. Currently this is implemented to be lazy and will
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.
Forces the retrieval of the resource map and metadata files. Files are retrieved asynchronously.
"""

self._reset()
# async re-fetch aggregation/resource map and metadata files form HydroShare
with multiprocessing.Pool() as pool:
pool.apply_async(self._refetch)
t = threading.Thread(target=self._refetch, daemon=True)
t.start()

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

0 comments on commit 78b1242

Please sign in to comment.