Skip to content

Commit c7a9211

Browse files
committed
feat: add FlowExecutionSubscriberComponent and FlowExecutionWatcherComponent for managing execution results
1 parent 2cac29a commit c7a9211

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"use client"
2+
3+
import React from "react"
4+
import {useSubscription} from "@apollo/client/react"
5+
import {ExecutionResult, Subscription} from "@code0-tech/sagittarius-graphql-types"
6+
import {FlowExecution, useFlowExecutionStore} from "@edition/flow/hooks/Flow.execution.hook"
7+
import {useService} from "@code0-tech/pictor"
8+
import {FlowService} from "@edition/flow/services/Flow.service"
9+
import flowExecutionResultSubscription from "@edition/flow/services/subscriptions/Flow.executionResult.subscription.graphql"
10+
11+
export interface FlowExecutionSubscriberComponentProps {
12+
execution: FlowExecution
13+
}
14+
15+
export const FlowExecutionSubscriberComponent: React.FC<FlowExecutionSubscriberComponentProps> = ({execution}) => {
16+
17+
const flowService = useService(FlowService)
18+
const removeExecution = useFlowExecutionStore(s => s.removeExecution)
19+
20+
useSubscription<Subscription>(flowExecutionResultSubscription, {
21+
variables: {executionIdentifier: execution.executionIdentifier},
22+
onData: (data) => {
23+
const executionResult = data.data.data?.namespacesProjectsFlowsExecutionResult?.executionResult as ExecutionResult | undefined
24+
if (executionResult) {
25+
flowService.addExecutionResult(execution.flowId, executionResult)
26+
removeExecution(execution.executionIdentifier)
27+
}
28+
},
29+
onComplete: () => removeExecution(execution.executionIdentifier),
30+
onError: () => removeExecution(execution.executionIdentifier),
31+
})
32+
33+
return null
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use client"
2+
3+
import React from "react"
4+
import {useFlowExecutionStore} from "@edition/flow/hooks/Flow.execution.hook"
5+
import {FlowExecutionSubscriberComponent} from "@edition/flow/components/FlowExecutionSubscriberComponent"
6+
7+
/**
8+
* Keeps one subscription alive per pending manual execution. Each subscriber writes
9+
* the incoming execution result into the flow store and drops the pending entry.
10+
*/
11+
export const FlowExecutionWatcherComponent: React.FC = () => {
12+
13+
const executions = useFlowExecutionStore(s => s.executions)
14+
15+
return <>
16+
{executions.map(execution => (
17+
<FlowExecutionSubscriberComponent
18+
key={execution.executionIdentifier}
19+
execution={execution}
20+
/>
21+
))}
22+
</>
23+
}

0 commit comments

Comments
 (0)