hyprstream_workers/runtime/
container.rs1use chrono::{DateTime, Utc};
7
8use hyprstream_rpc_std::worker_client::{ContainerState, KeyValue};
9use hyprstream_rpc_std::worker_client::ContainerMetadata;
11
12#[derive(Debug, Clone)]
17pub struct Container {
18 pub id: String,
20
21 pub pod_sandbox_id: String,
23
24 pub metadata: ContainerMetadata,
26
27 pub state: ContainerState,
29
30 pub created_at: DateTime<Utc>,
32
33 pub image: hyprstream_rpc_std::worker_client::ImageSpec,
35
36 pub labels: Vec<KeyValue>,
38
39 pub annotations: Vec<KeyValue>,
41
42 pub(crate) pid: Option<u32>,
45
46 pub(crate) exit_code: Option<i32>,
48}
49
50impl Container {
51 pub fn new(
53 id: String,
54 pod_sandbox_id: String,
55 config: &hyprstream_rpc_std::worker_client::ContainerConfig,
56 ) -> Self {
57 Self {
58 id,
59 pod_sandbox_id,
60 metadata: config.metadata.clone(),
61 state: ContainerState::ContainerCreated,
62 created_at: Utc::now(),
63 image: config.image.clone(),
64 labels: config.labels.clone(),
65 annotations: config.annotations.clone(),
66 pid: None,
67 exit_code: None,
68 }
69 }
70
71 #[allow(clippy::too_many_arguments)]
75 pub fn from_info(
76 id: String,
77 pod_sandbox_id: String,
78 metadata: ContainerMetadata,
79 image: hyprstream_rpc_std::worker_client::ImageSpec,
80 state: ContainerState,
81 created_at: DateTime<Utc>,
82 labels: Vec<KeyValue>,
83 annotations: Vec<KeyValue>,
84 ) -> Self {
85 Self {
86 id,
87 pod_sandbox_id,
88 metadata,
89 state,
90 created_at,
91 image,
92 labels,
93 annotations,
94 pid: None,
95 exit_code: None,
96 }
97 }
98
99 pub fn is_running(&self) -> bool {
101 self.state == ContainerState::ContainerRunning
102 }
103}