GraphEvent

sealed interface GraphEvent<out State>

A progress event emitted by CompiledGraph.stream and CompiledGraph.streamResume.

For every executed step a stream emits a NodeStarted for each node of the step, a NodeCompleted as each of them finishes, and then one StepCompleted. While a node runs, it can add NodeProgress events of its own, and a node that runs a subgraph adds a SubgraphEvent for every event of that graph. A node with a Retry adds a NodeRetry for each try that failed and is followed by another. A stream always ends with exactly one Completed or Interrupted. When a node calls interrupt, Interrupted comes right after the events of the nodes that had started, without a StepCompleted.

Inheritors

Types

Link copied to clipboard
data class Completed<out State>(val state: State) : GraphEvent<State>

Every branch reached END.

Link copied to clipboard
data class Interrupted<out State>(val state: State, val nextNodes: List<String>) : GraphEvent<State>

The run paused at an interrupt. nextNodes run when the thread is resumed. After an interrupt from a node, state is the state that node passed.

Link copied to clipboard
data class NodeCompleted<out State>(val step: Int, val node: String, val state: State) : GraphEvent<State>

node finished in step. state is what the node returned, or for a node with a work and an update, its update applied to the state the node received. In a step with several nodes this is the node's own result, before it is combined with the others; the combined state arrives with StepCompleted.

Link copied to clipboard
data class NodeProgress<out State>(val step: Int, val node: String, val value: Any, val state: State) : GraphEvent<State>

node reported value with reportProgress while it ran in step. The events of a node arrive in the order the node reported them, after its NodeStarted and before its NodeCompleted.

Link copied to clipboard
data class NodeRetry<out State>(val step: Int, val node: String, val attempt: Int, val cause: Throwable, val pause: Duration, val state: State) : GraphEvent<State>

A try of node failed in step, and the node will run again because it has a Retry. The event arrives before the engine waits for pause. The node has one NodeStarted and one NodeCompleted, however often it is tried.

Link copied to clipboard
data class NodeStarted<out State>(val step: Int, val node: String, val state: State) : GraphEvent<State>

node is about to run in step. state is the state the node receives. When a step runs several nodes in parallel, all of their NodeStarted events come before the first NodeCompleted.

Link copied to clipboard
data class StepCompleted<out State>(val step: Int, val nodes: List<String>, val state: State) : GraphEvent<State>

A step finished: nodes ran (in parallel when there are several) and produced state.

Link copied to clipboard
data class SubgraphEvent<out State>(val step: Int, val node: String, val event: GraphEvent<*>, val state: State) : GraphEvent<State>

event happened inside the subgraph that node runs in step. A subgraph sends every event that a stream of its own would have, from the NodeStarted of its first node to its Completed or Interrupted, and they arrive after the NodeStarted of node and before its NodeCompleted. The steps inside event are those of the subgraph, which start at 1 on every visit.

Properties

Link copied to clipboard
abstract val state: State

The graph state at the time of the event.