dora_node_api/event_stream/event.rs
1use dora_arrow_convert::ArrowData;
2use dora_core::config::{DataId, NodeId, OperatorId};
3use dora_message::metadata::Metadata;
4
5/// Represents an incoming Dora event.
6///
7/// Events might be triggered by other nodes, by Dora itself, or by some external user input.
8///
9/// It's safe to ignore event types that are not relevant to the node.
10///
11/// This enum is marked as `non_exhaustive` because we might add additional
12/// variants in the future. Please ignore unknown event types instead of throwing an
13/// error to avoid breakage when updating Dora.
14#[derive(Debug)]
15#[non_exhaustive]
16#[allow(clippy::large_enum_variant)]
17pub enum Event {
18 /// An input was received from another node.
19 ///
20 /// This event corresponds to one of the `inputs` of the node as specified
21 /// in the dataflow YAML file.
22 Input {
23 /// The input ID, as specified in the YAML file.
24 ///
25 /// Note that this is not the output ID of the sender, but the ID
26 /// assigned to the input in the YAML file.
27 id: DataId,
28 /// Meta information about this input, e.g. the timestamp.
29 metadata: Metadata,
30 /// The actual data in the Apache Arrow data format.
31 data: ArrowData,
32 },
33 /// An input was closed by the sender.
34 ///
35 /// The sending node mapped to an input exited, so this input will receive
36 /// no more data.
37 InputClosed {
38 /// The ID of the input that was closed, as specified in the YAML file.
39 ///
40 /// Note that this is not the output ID of the sender, but the ID
41 /// assigned to the input in the YAML file.
42 id: DataId,
43 },
44 /// A previously closed input has recovered and will receive data again.
45 ///
46 /// This happens when an upstream node that timed out (via `input_timeout`)
47 /// starts producing data again. The circuit breaker automatically re-opens
48 /// the input.
49 InputRecovered {
50 /// The ID of the recovered input, as specified in the YAML file.
51 id: DataId,
52 },
53 /// An upstream node has restarted.
54 ///
55 /// Sent to downstream nodes when a node with a restart policy successfully
56 /// restarts after a failure. Nodes can use this to reset state, clear caches,
57 /// or log the recovery.
58 NodeRestarted {
59 /// The ID of the upstream node that restarted.
60 id: NodeId,
61 },
62 /// Notification that the event stream is about to close.
63 ///
64 /// The [`StopCause`] field contains the reason for the event stream closure.
65 ///
66 /// Nodes should exit once the event stream closes.
67 Stop(StopCause),
68 /// Instructs the node to reload itself or one of its operators.
69 ///
70 /// This event is currently only used for reloading Python operators that are
71 /// started by a `dora runtime` process. So this event should not be sent to normal
72 /// nodes yet.
73 Reload {
74 /// The ID of the operator that should be reloaded.
75 ///
76 /// There is currently no case where `operator_id` is `None`.
77 operator_id: Option<OperatorId>,
78 },
79 /// A runtime parameter has been updated via `dora param set`.
80 ///
81 /// Nodes can use this to dynamically adjust behavior (e.g., thresholds,
82 /// rates) without restarting.
83 ParamUpdate {
84 /// The parameter key that was set.
85 key: String,
86 /// The new JSON value.
87 value: serde_json::Value,
88 },
89 /// A runtime parameter has been deleted via `dora param delete`.
90 ///
91 /// Nodes can use this to remove local overrides and fall back to defaults.
92 ParamDeleted {
93 /// The parameter key that was deleted.
94 key: String,
95 },
96 /// An upstream node has failed.
97 ///
98 /// Sent to downstream nodes when an upstream node exits with a
99 /// non-zero exit code. Downstream nodes can use this to handle
100 /// the failure gracefully (e.g. switch to cached data, log, retry).
101 NodeFailed {
102 /// The IDs of the inputs affected by the failure.
103 affected_input_ids: Vec<DataId>,
104 /// Human-readable error message from the failed node.
105 error: String,
106 /// The ID of the node that failed.
107 source_node_id: NodeId,
108 },
109 /// Notifies the node about an unexpected error that happened inside Dora.
110 ///
111 /// It's a good idea to output or log this error for debugging.
112 Error(String),
113}
114
115/// The reason for closing the event stream.
116///
117/// This enum is marked as `non_exhaustive` because we might add additional
118/// variants in the future.
119#[derive(Debug, Clone)]
120#[non_exhaustive]
121pub enum StopCause {
122 /// The dataflow is stopped early after a `dora stop` command (or on `ctrl-c`).
123 ///
124 /// Nodes should exit as soon as possible if they receive a stop event of
125 /// this type. Dora will kill nodes that keep running for too long after
126 /// receiving such a stop event.
127 Manual,
128 /// The event stream is closed because all of the node's inputs were closed.
129 ///
130 /// This stop event type is only sent for nodes that have at least one input.
131 AllInputsClosed,
132}