Skip to content

Commit

Permalink
feat: enrich /workflows/{workflow_id} route with workflow metadata,…
Browse files Browse the repository at this point in the history
… just like in `/wokrflows/{workflow_id}/runs`
  • Loading branch information
Kiryous committed Jan 7, 2025
1 parent 1b47ff4 commit f3a512d
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions keep/api/routes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,36 @@ def get_workflow_by_id(
tenant_id = authenticated_entity.tenant_id
# get all workflow
workflow = get_workflow(tenant_id=tenant_id, workflow_id=workflow_id)

if not workflow:
logger.warning(
f"Tenant tried to get workflow {workflow_id} that does not exist",
extra={"tenant_id": tenant_id},
)
raise HTTPException(404, "Workflow not found")

installed_providers = get_installed_providers(tenant_id)
installed_providers_by_type = {}
for installed_provider in installed_providers:
if installed_provider.type not in installed_providers_by_type:
installed_providers_by_type[installed_provider.type] = {

Check warning on line 570 in keep/api/routes/workflows.py

View check run for this annotation

Codecov / codecov/patch

keep/api/routes/workflows.py#L566-L570

Added lines #L566 - L570 were not covered by tests
installed_provider.name: installed_provider
}
else:
installed_providers_by_type[installed_provider.type][

Check warning on line 574 in keep/api/routes/workflows.py

View check run for this annotation

Codecov / codecov/patch

keep/api/routes/workflows.py#L574

Added line #L574 was not covered by tests
installed_provider.name
] = installed_provider

workflowstore = WorkflowStore()
try:
providers_dto, triggers = workflowstore.get_workflow_meta_data(

Check warning on line 580 in keep/api/routes/workflows.py

View check run for this annotation

Codecov / codecov/patch

keep/api/routes/workflows.py#L578-L580

Added lines #L578 - L580 were not covered by tests
tenant_id=tenant_id,
workflow=workflow,
installed_providers_by_type=installed_providers_by_type,
)
except Exception as e:
logger.error(f"Error fetching workflow meta data: {e}")
providers_dto, triggers = [], [] # Default in case of failure

Check warning on line 587 in keep/api/routes/workflows.py

View check run for this annotation

Codecov / codecov/patch

keep/api/routes/workflows.py#L585-L587

Added lines #L585 - L587 were not covered by tests

try:
workflow_yaml = yaml.safe_load(workflow.workflow_raw)
valid_workflow_yaml = {"workflow": workflow_yaml}
Expand All @@ -575,13 +597,11 @@ def get_workflow_by_id(
created_by=workflow.created_by,
creation_time=workflow.creation_time,
interval=workflow.interval,
providers=[],
triggers=[],
providers=providers_dto,
triggers=triggers,
workflow_raw=final_workflow_raw,
revision=workflow.revision,
last_updated=workflow.last_updated,
disabled=workflow.is_disabled,
provisioned=workflow.provisioned,
)
return workflow_dto
except yaml.YAMLError:
Expand Down

0 comments on commit f3a512d

Please sign in to comment.