dora_node_api/event_stream/
event.rs

1use dora_arrow_convert::ArrowData;
2use dora_core::config::{DataId, 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    /// Notification that the event stream is about to close.
45    ///
46    /// The [`StopCause`] field contains the reason for the event stream closure.
47    ///
48    /// Typically, nodes should exit once the event stream closes. One notable
49    /// exception are nodes with no inputs, which will receive aa
50    /// `Event::Stop(StopCause::AllInputsClosed)` right at startup. Source nodes
51    /// might want to keep producing outputs still. (There is currently an open
52    /// discussion of changing this behavior and not sending `AllInputsClosed`
53    /// to nodes without inputs.)
54    ///
55    /// Note: Stop events with `StopCause::Manual` indicate a manual stop operation
56    /// issued through `dora stop` or a `ctrl-c`. Nodes **must exit** once receiving
57    /// such a stop event, otherwise they will be killed by Dora.
58    Stop(StopCause),
59    /// Instructs the node to reload itself or one of its operators.
60    ///
61    /// This event is currently only used for reloading Python operators that are
62    /// started by a `dora runtime` process. So this event should not be sent to normal
63    /// nodes yet.
64    Reload {
65        /// The ID of the operator that should be reloaded.
66        ///
67        /// There is currently no case where `operator_id` is `None`.
68        operator_id: Option<OperatorId>,
69    },
70    /// Notifies the node about an unexpected error that happened inside Dora.
71    ///
72    /// It's a good idea to output or log this error for debugging.
73    Error(String),
74}
75
76/// The reason for closing the event stream.
77///
78/// This enum is marked as `non_exhaustive` because we might add additional
79/// variants in the future.
80#[derive(Debug, Clone)]
81#[non_exhaustive]
82pub enum StopCause {
83    /// The dataflow is stopped early after a `dora stop` command (or on `ctrl-c`).
84    ///
85    /// Nodes should exit as soon as possible if they receive a stop event of
86    /// this type. Dora will kill nodes that keep running for too long after
87    /// receiving such a stop event.
88    Manual,
89    /// The event stream is closed because all of the node's inputs were closed.
90    AllInputsClosed,
91}