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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Remote storage flag removal #1101

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion backend/backend/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ class FeatureFlag:
"""Temporary feature flags."""

APP_DEPLOYMENT = "app_deployment"
REMOTE_FILE_STORAGE = "remote_file_storage"
53 changes: 16 additions & 37 deletions backend/prompt_studio/prompt_studio_core_v2/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import logging
import shutil
import uuid
from typing import Any

from account_v2.models import User
from adapter_processor_v2.models import AdapterInstance
from django.db import models
from django.db.models import QuerySet
from file_management.file_management_helper import FileManagerHelper
from prompt_studio.prompt_studio_core_v2.constants import DefaultPrompts
from unstract.sdk.file_storage.constants import StorageType
from unstract.sdk.file_storage.env_helper import EnvHelper
Expand All @@ -19,9 +17,6 @@
DefaultOrganizationMixin,
)

from backend.constants import FeatureFlag
from unstract.flags.feature_flag import check_feature_flag_status

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -140,38 +135,22 @@ class CustomTool(DefaultOrganizationMixin, BaseModel):

def delete(self, organization_id=None, *args, **kwargs):
# Delete the documents associated with the tool
if not check_feature_flag_status(FeatureFlag.REMOTE_FILE_STORAGE):
file_path = FileManagerHelper.handle_sub_directory_for_tenants(
organization_id,
is_create=False,
user_id=self.created_by.user_id,
tool_id=str(self.tool_id),
)
if organization_id:
try:
shutil.rmtree(file_path)
except FileNotFoundError:
logger.error(f"The folder {file_path} does not exist.")
except OSError as e:
logger.error(f"Error: {file_path} : {e.strerror}")
# Continue with the deletion of the tool
else:
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
file_path = PromptStudioFileHelper.get_or_create_prompt_studio_subdirectory(
organization_id,
is_create=False,
user_id=self.created_by.user_id,
tool_id=str(self.tool_id),
)
try:
fs_instance.rm(file_path, True)
except FileNotFoundError:
# Supressed to handle cases when the remote
# file is missing or already deleted
pass
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
file_path = PromptStudioFileHelper.get_or_create_prompt_studio_subdirectory(
organization_id,
is_create=False,
user_id=self.created_by.user_id,
tool_id=str(self.tool_id),
)
try:
fs_instance.rm(file_path, True)
except FileNotFoundError:
# Supressed to handle cases when the remote
# file is missing or already deleted
pass
super().delete(*args, **kwargs)

class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from unstract.sdk.constants import LogLevel
from unstract.sdk.tool.stream import StreamMixin

from backend.constants import FeatureFlag
from unstract.flags.feature_flag import check_feature_flag_status


class PromptIdeBaseTool(StreamMixin):
def __init__(self, log_level: LogLevel = LogLevel.INFO, org_id: str = "") -> None:
Expand All @@ -20,11 +17,11 @@ def __init__(self, log_level: LogLevel = LogLevel.INFO, org_id: str = "") -> Non
self.log_level = log_level
self.org_id = org_id
self.workflow_filestorage = None
if check_feature_flag_status(FeatureFlag.REMOTE_FILE_STORAGE):
from unstract.filesystem import FileStorageType, FileSystem

file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
self.workflow_filestorage = file_system.get_file_storage()
from unstract.filesystem import FileStorageType, FileSystem

file_system = FileSystem(FileStorageType.WORKFLOW_EXECUTION)
self.workflow_filestorage = file_system.get_file_storage()

super().__init__(log_level=log_level)

Expand Down
Loading