Skip to content

Commit

Permalink
Merge pull request #99 from PySpur-Dev/bugfix/reset-run-issues
Browse files Browse the repository at this point in the history
Bugfix/reset run issues
  • Loading branch information
srijanpatel authored Jan 18, 2025
2 parents 1af8890 + 2526a12 commit 6425ff1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
8 changes: 8 additions & 0 deletions frontend/src/components/nodes/InputNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import styles from './InputNode.module.css'
import { RootState } from '../../store/store'
import { isEqual } from 'lodash'
import { FlowWorkflowNode } from '../../store/flowSlice'
import NodeOutputDisplay from './NodeOutputDisplay'

interface InputNodeProps {
id: string
Expand All @@ -28,6 +29,7 @@ const InputNode: React.FC<InputNodeProps> = ({ id, data, readOnly = false, ...pr
const [newFieldValue, setNewFieldValue] = useState<string>('')
const [isCollapsed, setIsCollapsed] = useState<boolean>(false)
const [showKeyError, setShowKeyError] = useState<boolean>(false)
const [showOutput, setShowOutput] = useState(false)
const incomingEdges = useSelector(
(state: RootState) => state.flow.edges.filter((edge) => edge.target === id),
isEqual
Expand Down Expand Up @@ -341,6 +343,12 @@ const InputNode: React.FC<InputNodeProps> = ({ id, data, readOnly = false, ...pr
{renderWorkflowInputs()}
{renderAddField()}
</div>

{data.run && (
<div className="mt-2">
<NodeOutputDisplay output={data.run} />
</div>
)}
</BaseNode>
</div>
)
Expand Down
26 changes: 18 additions & 8 deletions frontend/src/hooks/useWorkflowExecution.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react'
import { useState, useEffect, useRef } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { updateNodeDataOnly, resetRun } from '../store/flowSlice'
import { getRunStatus, startRun, getWorkflowRuns, validateGoogleAccessToken } from '../utils/api'
Expand Down Expand Up @@ -26,13 +26,14 @@ export const useWorkflowExecution = ({ onAlert }: UseWorkflowExecutionProps) =>
const [workflowRuns, setWorkflowRuns] = useState<WorkflowRun[]>([])
const [isUpdatingStatus, setIsUpdatingStatus] = useState<boolean>(false)

let currentStatusInterval: NodeJS.Timeout | null = null
// Create array to track all intervals for this run
const statusIntervals = useRef<NodeJS.Timeout[]>([])

const updateWorkflowStatus = async (runID: string): Promise<void> => {
if (currentStatusInterval) {
clearInterval(currentStatusInterval)
}
currentStatusInterval = setInterval(async () => {
// Clear any existing intervals
statusIntervals.current.forEach((interval) => clearInterval(interval))

let currentStatusInterval = setInterval(async () => {
try {
const statusResponse = await getRunStatus(runID)
const tasks = statusResponse.tasks
Expand Down Expand Up @@ -84,21 +85,30 @@ export const useWorkflowExecution = ({ onAlert }: UseWorkflowExecutionProps) =>
if (statusResponse.status !== 'RUNNING') {
setIsRunning(false)
setCompletionPercentage(0)
// Clear all intervals
statusIntervals.current.forEach((interval) => clearInterval(interval))
clearInterval(currentStatusInterval)
onAlert('Workflow run completed.', 'success')
}
if (statusResponse.status === 'FAILED' || tasks.some((task) => task.status === 'FAILED')) {
setIsRunning(false)
setCompletionPercentage(0)
// Clear all intervals
statusIntervals.current.forEach((interval) => clearInterval(interval))
clearInterval(currentStatusInterval)
onAlert('Workflow run failed.', 'danger')
return
}
} catch (error) {
console.error('Error fetching workflow status:', error)
// Clear all intervals
statusIntervals.current.forEach((interval) => clearInterval(interval))
clearInterval(currentStatusInterval)
}
}, 1000)

// Track the new interval
statusIntervals.current.push(currentStatusInterval)
}

const executeWorkflow = async (inputValues: Record<string, any>): Promise<void> => {
Expand Down Expand Up @@ -132,8 +142,8 @@ export const useWorkflowExecution = ({ onAlert }: UseWorkflowExecutionProps) =>
const stopWorkflow = (): void => {
setIsRunning(false)
setCompletionPercentage(0)
if (currentStatusInterval) {
clearInterval(currentStatusInterval)
if (statusIntervals.current.length > 0) {
statusIntervals.current.forEach((interval) => clearInterval(interval))
}
onAlert('Workflow run stopped.', 'warning')
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/store/flowSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ const flowSlice = createSlice({
resetRun: (state) => {
state.nodes = state.nodes.map((node) => ({
...node,
data: { ...node.data, run: undefined, taskStatus: undefined },
data: { ...node.data, run: undefined, taskStatus: undefined, error: undefined },
}))
},

Expand Down

0 comments on commit 6425ff1

Please sign in to comment.