Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface LogRowContextMenuProps {
onOpenPreview: () => void
onToggleWorkflowFilter: () => void
onClearAllFilters: () => void
onCancelExecution: () => void
isFilteredByThisWorkflow: boolean
hasActiveFilters: boolean
}
Expand All @@ -41,11 +42,13 @@ export const LogRowContextMenu = memo(function LogRowContextMenu({
onOpenPreview,
onToggleWorkflowFilter,
onClearAllFilters,
onCancelExecution,
isFilteredByThisWorkflow,
hasActiveFilters,
}: LogRowContextMenuProps) {
const hasExecutionId = Boolean(log?.executionId)
const hasWorkflow = Boolean(log?.workflow?.id || log?.workflowId)
const isRunning = log?.status === 'running' && hasExecutionId && hasWorkflow

return (
<DropdownMenu open={isOpen} onOpenChange={(open) => !open && onClose()} modal={false}>
Expand All @@ -69,6 +72,15 @@ export const LogRowContextMenu = memo(function LogRowContextMenu({
sideOffset={4}
onCloseAutoFocus={(e) => e.preventDefault()}
>
{isRunning && (
<>
<DropdownMenuItem onSelect={onCancelExecution} className='text-destructive'>
<X />
Cancel Execution
</DropdownMenuItem>
<DropdownMenuSeparator />
</>
)}
<DropdownMenuItem disabled={!hasExecutionId} onSelect={onCopyExecutionId}>
<Copy />
Copy Execution ID
Expand Down
13 changes: 13 additions & 0 deletions apps/sim/app/workspace/[workspaceId]/logs/logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { getBlock } from '@/blocks/registry'
import { useFolderMap, useFolders } from '@/hooks/queries/folders'
import {
prefetchLogDetail,
useCancelExecution,
useDashboardStats,
useLogDetail,
useLogsList,
Expand Down Expand Up @@ -534,6 +535,17 @@ export default function Logs() {
}
}, [contextMenuLog])

const cancelExecution = useCancelExecution()

const handleCancelExecution = useCallback(() => {
const workflowId = contextMenuLog?.workflow?.id || contextMenuLog?.workflowId
const executionId = contextMenuLog?.executionId
if (workflowId && executionId) {
cancelExecution.mutate({ workflowId, executionId })
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [contextMenuLog])

const contextMenuWorkflowId = contextMenuLog?.workflow?.id || contextMenuLog?.workflowId
const isFilteredByThisWorkflow = Boolean(
contextMenuWorkflowId && workflowIds.length === 1 && workflowIds[0] === contextMenuWorkflowId
Expand Down Expand Up @@ -1178,6 +1190,7 @@ export default function Logs() {
onCopyLink={handleCopyLink}
onOpenWorkflow={handleOpenWorkflow}
onOpenPreview={handleOpenPreview}
onCancelExecution={handleCancelExecution}
onToggleWorkflowFilter={handleToggleWorkflowFilter}
onClearAllFilters={handleClearAllFilters}
isFilteredByThisWorkflow={isFilteredByThisWorkflow}
Expand Down
28 changes: 28 additions & 0 deletions apps/sim/hooks/queries/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import {
keepPreviousData,
type QueryClient,
useInfiniteQuery,
useMutation,
useQuery,
useQueryClient,
} from '@tanstack/react-query'
import { getEndDateFromTimeRange, getStartDateFromTimeRange } from '@/lib/logs/filters'
import { parseQuery, queryToApiParams } from '@/lib/logs/query-parser'
Expand Down Expand Up @@ -273,3 +275,29 @@ export function useExecutionSnapshot(executionId: string | undefined) {
staleTime: 5 * 60 * 1000, // 5 minutes - execution snapshots don't change
})
}

export function useCancelExecution() {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async ({
workflowId,
executionId,
}: {
workflowId: string
executionId: string
}) => {
const res = await fetch(`/api/workflows/${workflowId}/executions/${executionId}/cancel`, {
method: 'POST',
})
if (!res.ok) throw new Error('Failed to cancel execution')
const data = await res.json()
if (!data.success) throw new Error('Failed to cancel execution')
return data
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: logKeys.lists() })
queryClient.invalidateQueries({ queryKey: logKeys.details() })
queryClient.invalidateQueries({ queryKey: [...logKeys.all, 'stats'] })
},
})
}
Loading