shared/models/server/
events.rs

1use crate::models::EventEmittingModel;
2use std::sync::LazyLock;
3
4#[non_exhaustive]
5pub enum ServerEvent {
6    /// Emitted when a server transfer starts.
7    TransferStarted {
8        server: Box<super::Server>,
9        destination_node: Box<crate::models::node::Node>,
10        destination_allocation: Option<uuid::Uuid>,
11        destination_allocations: Vec<uuid::Uuid>,
12    },
13    /// Emitted when a server transfer completes, either successfully or unsuccessfully.
14    TransferCompleted {
15        server: Box<super::Server>,
16        destination_node: Box<crate::models::node::Node>,
17        successful: bool,
18    },
19    /// Emitted when a server installation starts.
20    InstallStarted {
21        server: Box<super::Server>,
22        installation_script: Box<wings_api::InstallationScript>,
23    },
24    /// Emitted when a server installation completes, either successfully or unsuccessfully.
25    InstallCompleted {
26        server: Box<super::Server>,
27        successful: bool,
28    },
29    /// Emitted when a server's state is reset manually (such as via an API call).
30    /// If you handle this you might also want to handle `NodeEvent::StateReset` as well. (Called when the node restarts)
31    StateReset { server: Box<super::Server> },
32}
33
34#[async_trait::async_trait]
35impl EventEmittingModel for super::Server {
36    type Event = ServerEvent;
37
38    fn get_event_emitter() -> &'static crate::events::EventEmitter<Self::Event> {
39        static EVENT_EMITTER: LazyLock<crate::events::EventEmitter<ServerEvent>> =
40            LazyLock::new(crate::events::EventEmitter::default);
41
42        &EVENT_EMITTER
43    }
44}