Fix bug with downloaded file getting their file path added, fix bug with azure blob path (#3592)
Co-authored-by: Suchintan Singh <suchintan@skyvern.com>
This commit is contained in:
@@ -547,6 +547,7 @@ class ForgeAgent:
|
|||||||
final_file_name = f"download-{datetime.now().strftime('%Y%m%d%H%M%S%f')}-{random_file_id}"
|
final_file_name = f"download-{datetime.now().strftime('%Y%m%d%H%M%S%f')}-{random_file_id}"
|
||||||
|
|
||||||
# Check if file with this name already exists
|
# Check if file with this name already exists
|
||||||
|
final_file_name = final_file_name
|
||||||
target_path = os.path.join(workflow_download_directory, final_file_name + file_extension)
|
target_path = os.path.join(workflow_download_directory, final_file_name + file_extension)
|
||||||
counter = 1
|
counter = 1
|
||||||
while os.path.exists(target_path):
|
while os.path.exists(target_path):
|
||||||
@@ -555,7 +556,7 @@ class ForgeAgent:
|
|||||||
target_path = os.path.join(workflow_download_directory, final_file_name + file_extension)
|
target_path = os.path.join(workflow_download_directory, final_file_name + file_extension)
|
||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
rename_file(os.path.join(workflow_download_directory, file), target_path)
|
rename_file(os.path.join(workflow_download_directory, file), final_file_name + file_extension)
|
||||||
|
|
||||||
LOG.info(
|
LOG.info(
|
||||||
"Task marked as completed due to download",
|
"Task marked as completed due to download",
|
||||||
|
|||||||
@@ -1983,13 +1983,24 @@ class FileUploadBlock(Block):
|
|||||||
|
|
||||||
def _get_s3_uri(self, workflow_run_id: str, path: str) -> str:
|
def _get_s3_uri(self, workflow_run_id: str, path: str) -> str:
|
||||||
folder_path = self.path or f"{workflow_run_id}"
|
folder_path = self.path or f"{workflow_run_id}"
|
||||||
|
# Remove trailing slash from folder_path to avoid double slashes
|
||||||
|
folder_path = folder_path.rstrip("/")
|
||||||
|
# Remove any empty path segments to avoid double slashes
|
||||||
|
folder_path = "/".join(segment for segment in folder_path.split("/") if segment)
|
||||||
s3_suffix = f"{uuid.uuid4()}_{Path(path).name}"
|
s3_suffix = f"{uuid.uuid4()}_{Path(path).name}"
|
||||||
return f"s3://{self.s3_bucket}/{folder_path}/{s3_suffix}"
|
return f"s3://{self.s3_bucket}/{folder_path}/{s3_suffix}"
|
||||||
|
|
||||||
def _get_azure_blob_uri(self, workflow_run_id: str, file_path: str) -> str:
|
def _get_azure_blob_name(self, workflow_run_id: str, file_path: str) -> str:
|
||||||
blob_name = Path(file_path).name
|
blob_name = f"{uuid.uuid4()}_{Path(file_path).name}"
|
||||||
folder_path = self.path or workflow_run_id
|
folder_path = self.path or workflow_run_id
|
||||||
return f"https://{self.azure_storage_account_name}.blob.core.windows.net/{self.azure_blob_container_name}/{folder_path}/{uuid.uuid4()}_{blob_name}"
|
# Remove trailing slash from folder_path to avoid double slashes
|
||||||
|
folder_path = folder_path.rstrip("/")
|
||||||
|
# Remove any empty path segments to avoid double slashes
|
||||||
|
folder_path = "/".join(segment for segment in folder_path.split("/") if segment)
|
||||||
|
return folder_path + "/" + blob_name
|
||||||
|
|
||||||
|
def _get_azure_blob_uri(self, workflow_run_id: str, blob_name: str) -> str:
|
||||||
|
return f"https://{self.azure_storage_account_name}.blob.core.windows.net/{self.azure_blob_container_name}/{blob_name}"
|
||||||
|
|
||||||
async def execute(
|
async def execute(
|
||||||
self,
|
self,
|
||||||
@@ -2115,8 +2126,9 @@ class FileUploadBlock(Block):
|
|||||||
storage_account_key=actual_azure_storage_account_key,
|
storage_account_key=actual_azure_storage_account_key,
|
||||||
)
|
)
|
||||||
for file_path in files_to_upload:
|
for file_path in files_to_upload:
|
||||||
blob_name = Path(file_path).name
|
LOG.info("FileUploadBlock: Uploading file to Azure Blob Storage", file_path=file_path)
|
||||||
azure_uri = self._get_azure_blob_uri(workflow_run_id, file_path)
|
blob_name = self._get_azure_blob_name(workflow_run_id, file_path)
|
||||||
|
azure_uri = self._get_azure_blob_uri(workflow_run_id, blob_name)
|
||||||
uploaded_uris.append(azure_uri)
|
uploaded_uris.append(azure_uri)
|
||||||
await azure_client.upload_file_from_path(
|
await azure_client.upload_file_from_path(
|
||||||
container_name=self.azure_blob_container_name or "", blob_name=blob_name, file_path=file_path
|
container_name=self.azure_blob_container_name or "", blob_name=blob_name, file_path=file_path
|
||||||
|
|||||||
Reference in New Issue
Block a user