Skip to content

Commit

Permalink
remove cached step for memory workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranjali Basmatkar authored and Pranjali Basmatkar committed Jul 14, 2023
1 parent f9d112a commit 1565658
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tango/step_caches/memory_step_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def __setitem__(self, step: Step, value: Any) -> None:
UserWarning,
)

def __delitem__(self, step_unique_id) -> None:
if step_unique_id in self.cache:
del self.cache[step_unique_id]
else:
raise KeyError(f"{step_unique_id} not present in the memory cache. Can't be deleted")

def __contains__(self, step: object) -> bool:
if isinstance(step, (Step, StepInfo)):
return step.unique_id in self.cache
Expand Down
11 changes: 11 additions & 0 deletions tango/workspaces/memory_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def step_failed(self, step: Step, e: BaseException) -> None:
existing_step_info.end_time = utc_now_datetime()
existing_step_info.error = exception_to_string(e)

def step_cache_remove(self, step_unique_id: str) -> None:
"""
Get Step unique id from the user and remove the step information from memory cache
:raises KeyError: If no step with the unique name found in the cache dir
"""
try:
del self.unique_id_to_info[step_unique_id]
self.step_cache.__delitem__(step_unique_id)
except KeyError:
raise KeyError(f"{step_unique_id} step info not found, step cache cannot be deleted")

def register_run(self, targets: Iterable[Step], name: Optional[str] = None) -> Run:
if name is None:
name = petname.generate()
Expand Down

0 comments on commit 1565658

Please sign in to comment.