Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Junk metadata when script runs #1083

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/neptune/management/exceptions.py
Expand Up @@ -163,3 +163,8 @@ class BadRequestException(ManagementOperationFailure):
class IncorrectIdentifierException(ManagementOperationFailure):
code = 21
description = "Can not parse '{identifier}' as identifier."


class ObjectNotFound(ManagementOperationFailure):
code = 22
description = "Object not found."
3 changes: 2 additions & 1 deletion src/neptune/new/internal/backends/hosted_neptune_backend.py
Expand Up @@ -41,6 +41,7 @@
NeptuneException,
)
from neptune.common.patterns import PROJECT_QUALIFIED_NAME_PATTERN
from neptune.management.exceptions import ObjectNotFound
from neptune.new.envs import NEPTUNE_FETCH_TABLE_STEP_SIZE
from neptune.new.exceptions import (
AmbiguousProjectName,
Expand Down Expand Up @@ -303,7 +304,7 @@ def get_metadata_container(
)

return ApiExperiment.from_experiment(experiment)
except HTTPNotFound:
except ObjectNotFound:
raise MetadataContainerNotFound.of_container_type(
container_type=expected_container_type, container_id=container_id
)
Expand Down
5 changes: 5 additions & 0 deletions src/neptune/new/internal/backends/swagger_client_wrapper.py
Expand Up @@ -33,6 +33,7 @@ class ApiMethodWrapper:
PROJECT_NAME_COLLISION = "PROJECT_NAME_COLLISION"
PROJECT_KEY_INVALID = "PROJECT_KEY_INVALID"
PROJECT_NAME_INVALID = "PROJECT_NAME_INVALID"
EXPERIMENT_NOT_FOUND = "EXPERIMENT_NOT_FOUND"

def __init__(self, api_method):
self._api_method = api_method
Expand Down Expand Up @@ -78,6 +79,10 @@ def handle_neptune_http_errors(response, exception: Optional[HTTPError] = None):
raise ProjectNameInvalid(
name=body.get("name", "<unknown name>"), reason=body.get("reason", "Unknown reason")
) from exception
elif error_type == ApiMethodWrapper.EXPERIMENT_NOT_FOUND:
from neptune.management.exceptions import ObjectNotFound

raise ObjectNotFound() from exception
elif exception:
raise exception

Expand Down
17 changes: 17 additions & 0 deletions src/neptune/new/internal/disk_queue.py
Expand Up @@ -16,6 +16,7 @@
import json
import logging
import os
import shutil
import threading
from glob import glob
from pathlib import Path
Expand Down Expand Up @@ -152,6 +153,22 @@ def close(self):
self._last_ack_file.close()
self._last_put_file.close()

if self.is_empty():
self._remove_data()

def _remove_data(self):
path = self._dir_path
shutil.rmtree(path, ignore_errors=True)

parent = path.parent

files = os.listdir(parent)
if len(files) == 0:
try:
os.rmdir(parent)
except OSError:
_logger.info(f"Cannot remove directory: {parent}")

def wait_for_empty(self, seconds: Optional[float] = None) -> bool:
with self._empty_cond:
return self._empty_cond.wait_for(self.is_empty, timeout=seconds)
Expand Down
11 changes: 11 additions & 0 deletions tests/neptune/new/client/abstract_experiment_test_mixin.py
Expand Up @@ -129,6 +129,17 @@ def test_wrong_per_type_function(self):
with self.assertRaises(TypeDoesNotSupportAttributeException):
exp["some/path"].download()

def test_clean_data_on_stop(self):
exp = self.call_init(mode="async", flush_period=0.5)
container_path = exp._op_processor._queue._dir_path

assert os.path.exists(container_path)

exp.stop()

assert not os.path.exists(container_path)
assert not os.path.exists(container_path.parent)

@abstractmethod
def test_read_only_mode(self):
pass