Skip to content

Commit

Permalink
fix(api): slow workflows endpoint (keephq#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Apr 10, 2024
1 parent 49ccf0a commit 6d441e8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 73 deletions.
2 changes: 1 addition & 1 deletion keep-ui/app/workflows/[workflow_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function WorkflowDetailPage({
<TableBody>
{workflowExecutions.map((execution) => (
<TableRow key={execution.id}>
<TableCell>{execution.started}</TableCell>
<TableCell>{new Date(execution.started + "Z").toLocaleString()}</TableCell>
<TableCell>{execution.id}</TableCell>
<TableCell>{execution.triggered_by}</TableCell>
<TableCell>{execution.status}</TableCell>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ export default function WorkflowExecutionPage({
<TableCell className="w-1/4 break-words whitespace-normal">
{stepId}
</TableCell>
<TableCell className="w-3/4 break-words whitespace-normal">
<TableCell className="w-3/4 break-words whitespace-normal max-w-xl">
<Accordion>
<AccordionHeader>Value</AccordionHeader>
<AccordionBody>
<pre className="overflow-scroll max-w-lg">
<pre className="overflow-scroll">
{JSON.stringify(stepResults, null, 2)}
</pre>
</AccordionBody>
Expand All @@ -140,43 +140,61 @@ export default function WorkflowExecutionPage({
)}
<div className={Object.keys(results).length > 0 ? "mt-8" : ""}>
{executionStatus === "success" ? (
<Card>
<Title>Workflow Logs</Title>
<Table className="w-full">
<TableHead>
<TableRow>
<TableCell className="w-1/3 break-words whitespace-normal">
Timestamp
</TableCell>
<TableCell className="w-1/3 break-words whitespace-normal">
Message
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{logs.map((log, index) => (
<TableRow
className={`${
log.message?.includes("NOT to run")
? "bg-red-100"
: log.message?.includes("evaluated to run")
? "bg-green-100"
: ""
}`}
key={index}
>
<>
{error && (
<Callout
className="mt-4"
title="Error during workflow execution"
icon={ExclamationCircleIcon}
color="rose"
>
{error
? error.split("\n").map((line, index) => (
// Render each line as a separate paragraph or div.
// The key is index, which is sufficient for simple lists like this.
<p key={index}>{line}</p>
))
: "An unknown error occurred during execution."}
</Callout>
)}
<Card>
<Title>Workflow Logs</Title>
<Table className="w-full">
<TableHead>
<TableRow>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.timestamp}
Timestamp
</TableCell>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.message}
Message
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Card>
) : executionStatus === "in_progress" ? (
</TableHead>
<TableBody>
{logs.map((log, index) => (
<TableRow
className={`${
log.message?.includes("NOT to run")
? "bg-red-100"
: log.message?.includes("evaluated to run")
? "bg-green-100"
: ""
}`}
key={index}
>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.timestamp}
</TableCell>
<TableCell className="w-1/3 break-words whitespace-normal">
{log.message}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Card>
</>
) : (
<div>
<div className="flex items-center justify-center">
<p>
Expand All @@ -186,22 +204,6 @@ export default function WorkflowExecutionPage({
</div>
<Loading></Loading>
</div>
) : (
<Callout
className="mt-4"
title="Error during workflow execution"
icon={ExclamationCircleIcon}
color="rose"
>
{error
? error.split('\n').map((line, index) => (
// Render each line as a separate paragraph or div.
// The key is index, which is sufficient for simple lists like this.
<p key={index}>{line}</p>
))
: "An unknown error occurred during execution."
}
</Callout>
)}
</div>
</div>
Expand Down
22 changes: 11 additions & 11 deletions keep/api/routes/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,19 +386,19 @@ def get_workflow_by_id(
workflow_executions_dtos = []
with tracer.start_as_current_span("create_workflow_dtos"):
for workflow_execution in workflow_executions:
workflow_execution_dto = WorkflowExecutionDTO(
id=workflow_execution.id,
workflow_id=workflow_execution.workflow_id,
status=workflow_execution.status,
started=workflow_execution.started,
triggered_by=workflow_execution.triggered_by,
error=workflow_execution.error,
execution_time=workflow_execution.execution_time,
results=workflow_execution.results,
)
workflow_execution_dto = {
"id": workflow_execution.id,
"workflow_id": workflow_execution.workflow_id,
"status": workflow_execution.status,
"started": workflow_execution.started.isoformat(),
"triggered_by": workflow_execution.triggered_by,
"error": workflow_execution.error,
"execution_time": workflow_execution.execution_time,
"results": workflow_execution.results,
}
workflow_executions_dtos.append(workflow_execution_dto)

return workflow_executions_dtos
return JSONResponse(content=workflow_executions_dtos)


@router.delete("/{workflow_id}", description="Delete workflow")
Expand Down

0 comments on commit 6d441e8

Please sign in to comment.