Record logs into step artifacts (#1339)
Co-authored-by: Shuchang Zheng <wintonzheng0325@gmail.com> Co-authored-by: LawyZheng <lawyzheng1106@gmail.com> Co-authored-by: Nick Fisher <nick.fisher@avinium.com>
This commit is contained in:
@@ -51,6 +51,7 @@ from skyvern.forge.sdk.db.utils import (
|
||||
convert_to_workflow_run_output_parameter,
|
||||
convert_to_workflow_run_parameter,
|
||||
)
|
||||
from skyvern.forge.sdk.log_artifacts import save_workflow_run_logs
|
||||
from skyvern.forge.sdk.models import Step, StepStatus
|
||||
from skyvern.forge.sdk.schemas.observers import ObserverCruise, ObserverCruiseStatus, ObserverThought
|
||||
from skyvern.forge.sdk.schemas.organizations import Organization, OrganizationAuthToken
|
||||
@@ -808,6 +809,73 @@ class AgentDB:
|
||||
LOG.exception("UnexpectedError")
|
||||
raise
|
||||
|
||||
async def get_artifacts_by_entity_id(
|
||||
self,
|
||||
artifact_type: ArtifactType | None = None,
|
||||
task_id: str | None = None,
|
||||
step_id: str | None = None,
|
||||
workflow_run_id: str | None = None,
|
||||
workflow_run_block_id: str | None = None,
|
||||
observer_thought_id: str | None = None,
|
||||
observer_cruise_id: str | None = None,
|
||||
organization_id: str | None = None,
|
||||
) -> list[Artifact]:
|
||||
try:
|
||||
async with self.Session() as session:
|
||||
query = select(ArtifactModel)
|
||||
|
||||
if artifact_type is not None:
|
||||
query = query.filter_by(artifact_type=artifact_type)
|
||||
if task_id is not None:
|
||||
query = query.filter_by(task_id=task_id)
|
||||
if step_id is not None:
|
||||
query = query.filter_by(step_id=step_id)
|
||||
if workflow_run_id is not None:
|
||||
query = query.filter_by(workflow_run_id=workflow_run_id)
|
||||
if workflow_run_block_id is not None:
|
||||
query = query.filter_by(workflow_run_block_id=workflow_run_block_id)
|
||||
if observer_thought_id is not None:
|
||||
query = query.filter_by(observer_thought_id=observer_thought_id)
|
||||
if observer_cruise_id is not None:
|
||||
query = query.filter_by(observer_cruise_id=observer_cruise_id)
|
||||
if organization_id is not None:
|
||||
query = query.filter_by(organization_id=organization_id)
|
||||
|
||||
query = query.order_by(ArtifactModel.created_at.desc())
|
||||
if artifacts := (await session.scalars(query)).all():
|
||||
return [convert_to_artifact(artifact, self.debug_enabled) for artifact in artifacts]
|
||||
else:
|
||||
return []
|
||||
except SQLAlchemyError:
|
||||
LOG.error("SQLAlchemyError", exc_info=True)
|
||||
raise
|
||||
except Exception:
|
||||
LOG.error("UnexpectedError", exc_info=True)
|
||||
raise
|
||||
|
||||
async def get_artifact_by_entity_id(
|
||||
self,
|
||||
artifact_type: ArtifactType,
|
||||
task_id: str | None = None,
|
||||
step_id: str | None = None,
|
||||
workflow_run_id: str | None = None,
|
||||
workflow_run_block_id: str | None = None,
|
||||
observer_thought_id: str | None = None,
|
||||
observer_cruise_id: str | None = None,
|
||||
organization_id: str | None = None,
|
||||
) -> Artifact | None:
|
||||
artifacts = await self.get_artifacts_by_entity_id(
|
||||
artifact_type=artifact_type,
|
||||
task_id=task_id,
|
||||
step_id=step_id,
|
||||
workflow_run_id=workflow_run_id,
|
||||
workflow_run_block_id=workflow_run_block_id,
|
||||
observer_thought_id=observer_thought_id,
|
||||
observer_cruise_id=observer_cruise_id,
|
||||
organization_id=organization_id,
|
||||
)
|
||||
return artifacts[0] if artifacts else None
|
||||
|
||||
async def get_artifact(
|
||||
self,
|
||||
task_id: str,
|
||||
@@ -1183,6 +1251,7 @@ class AgentDB:
|
||||
workflow_run.failure_reason = failure_reason
|
||||
await session.commit()
|
||||
await session.refresh(workflow_run)
|
||||
await save_workflow_run_logs(workflow_run_id)
|
||||
return convert_to_workflow_run(workflow_run)
|
||||
LOG.error(
|
||||
"WorkflowRun not found, nothing to update",
|
||||
|
||||
Reference in New Issue
Block a user