support global workflow (#1664)

This commit is contained in:
Shuchang Zheng
2025-01-28 15:04:18 +08:00
committed by GitHub
parent 833cd8194e
commit 1b79ef9ca3
10 changed files with 154 additions and 26 deletions

View File

@@ -40,6 +40,10 @@ class BaseStorage(ABC):
def build_uri(self, artifact_id: str, step: Step, artifact_type: ArtifactType) -> str:
pass
@abstractmethod
async def retrieve_global_workflows(self) -> list[str]:
pass
@abstractmethod
def build_log_uri(self, log_entity_type: LogEntityType, log_entity_id: str, artifact_type: ArtifactType) -> str:
pass

View File

@@ -26,6 +26,17 @@ class LocalStorage(BaseStorage):
file_ext = FILE_EXTENTSION_MAP[artifact_type]
return f"file://{self.artifact_path}/{step.task_id}/{step.order:02d}_{step.retry_index}_{step.step_id}/{datetime.utcnow().isoformat()}_{artifact_id}_{artifact_type}.{file_ext}"
async def retrieve_global_workflows(self) -> list[str]:
file_path = Path(f"{self.artifact_path}/{settings.ENV}/global_workflows.txt")
self._create_directories_if_not_exists(file_path)
if not file_path.exists():
return []
try:
with open(file_path, "r") as f:
return [line.strip() for line in f.readlines() if line.strip()]
except Exception:
return []
def build_log_uri(self, log_entity_type: LogEntityType, log_entity_id: str, artifact_type: ArtifactType) -> str:
file_ext = FILE_EXTENTSION_MAP[artifact_type]
return f"file://{self.artifact_path}/logs/{log_entity_type}/{log_entity_id}/{datetime.utcnow().isoformat()}_{artifact_type}.{file_ext}"

View File

@@ -29,6 +29,13 @@ class S3Storage(BaseStorage):
file_ext = FILE_EXTENTSION_MAP[artifact_type]
return f"s3://{self.bucket}/{settings.ENV}/{step.task_id}/{step.order:02d}_{step.retry_index}_{step.step_id}/{datetime.utcnow().isoformat()}_{artifact_id}_{artifact_type}.{file_ext}"
async def retrieve_global_workflows(self) -> list[str]:
uri = f"s3://{self.bucket}/{settings.ENV}/global_workflows.txt"
data = await self.async_client.download_file(uri, log_exception=False)
if not data:
return []
return [line.strip() for line in data.decode("utf-8").split("\n") if line.strip()]
def build_log_uri(self, log_entity_type: LogEntityType, log_entity_id: str, artifact_type: ArtifactType) -> str:
file_ext = FILE_EXTENTSION_MAP[artifact_type]
return f"s3://{self.bucket}/{settings.ENV}/logs/{log_entity_type}/{log_entity_id}/{datetime.utcnow().isoformat()}_{artifact_type}.{file_ext}"