tangled
alpha
login
or
join now
lewis.moe
/
lewiscloud
0
fork
atom
Demonstrating core cloud concepts, starting with CaaS. Not for production use.
0
fork
atom
overview
issues
pulls
pipelines
Slightly better worker manager
lewis.moe
4 months ago
861139ae
a5fb0428
+255
-12
3 changed files
expand all
collapse all
unified
split
worker-plane
worker-manager
Cargo.lock
Cargo.toml
src
main.rs
+179
-3
worker-plane/worker-manager/Cargo.lock
···
446
446
]
447
447
448
448
[[package]]
449
449
+
name = "ntapi"
450
450
+
version = "0.4.1"
451
451
+
source = "registry+https://github.com/rust-lang/crates.io-index"
452
452
+
checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4"
453
453
+
dependencies = [
454
454
+
"winapi",
455
455
+
]
456
456
+
457
457
+
[[package]]
449
458
name = "nu-ansi-term"
450
459
version = "0.50.3"
451
460
source = "registry+https://github.com/rust-lang/crates.io-index"
···
455
464
]
456
465
457
466
[[package]]
467
467
+
name = "objc2-core-foundation"
468
468
+
version = "0.3.2"
469
469
+
source = "registry+https://github.com/rust-lang/crates.io-index"
470
470
+
checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536"
471
471
+
dependencies = [
472
472
+
"bitflags",
473
473
+
]
474
474
+
475
475
+
[[package]]
476
476
+
name = "objc2-io-kit"
477
477
+
version = "0.3.2"
478
478
+
source = "registry+https://github.com/rust-lang/crates.io-index"
479
479
+
checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15"
480
480
+
dependencies = [
481
481
+
"libc",
482
482
+
"objc2-core-foundation",
483
483
+
]
484
484
+
485
485
+
[[package]]
458
486
name = "once_cell"
459
487
version = "1.21.3"
460
488
source = "registry+https://github.com/rust-lang/crates.io-index"
···
524
552
"libc",
525
553
"redox_syscall",
526
554
"smallvec",
527
527
-
"windows-link",
555
555
+
"windows-link 0.2.1",
528
556
]
529
557
530
558
[[package]]
···
818
846
]
819
847
820
848
[[package]]
849
849
+
name = "sysinfo"
850
850
+
version = "0.37.2"
851
851
+
source = "registry+https://github.com/rust-lang/crates.io-index"
852
852
+
checksum = "16607d5caffd1c07ce073528f9ed972d88db15dd44023fa57142963be3feb11f"
853
853
+
dependencies = [
854
854
+
"libc",
855
855
+
"memchr",
856
856
+
"ntapi",
857
857
+
"objc2-core-foundation",
858
858
+
"objc2-io-kit",
859
859
+
"windows",
860
860
+
]
861
861
+
862
862
+
[[package]]
821
863
name = "tempfile"
822
864
version = "3.23.0"
823
865
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1068
1110
]
1069
1111
1070
1112
[[package]]
1113
1113
+
name = "winapi"
1114
1114
+
version = "0.3.9"
1115
1115
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1116
1116
+
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
1117
1117
+
dependencies = [
1118
1118
+
"winapi-i686-pc-windows-gnu",
1119
1119
+
"winapi-x86_64-pc-windows-gnu",
1120
1120
+
]
1121
1121
+
1122
1122
+
[[package]]
1123
1123
+
name = "winapi-i686-pc-windows-gnu"
1124
1124
+
version = "0.4.0"
1125
1125
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1126
1126
+
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
1127
1127
+
1128
1128
+
[[package]]
1129
1129
+
name = "winapi-x86_64-pc-windows-gnu"
1130
1130
+
version = "0.4.0"
1131
1131
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1132
1132
+
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
1133
1133
+
1134
1134
+
[[package]]
1135
1135
+
name = "windows"
1136
1136
+
version = "0.61.3"
1137
1137
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1138
1138
+
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
1139
1139
+
dependencies = [
1140
1140
+
"windows-collections",
1141
1141
+
"windows-core",
1142
1142
+
"windows-future",
1143
1143
+
"windows-link 0.1.3",
1144
1144
+
"windows-numerics",
1145
1145
+
]
1146
1146
+
1147
1147
+
[[package]]
1148
1148
+
name = "windows-collections"
1149
1149
+
version = "0.2.0"
1150
1150
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1151
1151
+
checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8"
1152
1152
+
dependencies = [
1153
1153
+
"windows-core",
1154
1154
+
]
1155
1155
+
1156
1156
+
[[package]]
1157
1157
+
name = "windows-core"
1158
1158
+
version = "0.61.2"
1159
1159
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1160
1160
+
checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
1161
1161
+
dependencies = [
1162
1162
+
"windows-implement",
1163
1163
+
"windows-interface",
1164
1164
+
"windows-link 0.1.3",
1165
1165
+
"windows-result",
1166
1166
+
"windows-strings",
1167
1167
+
]
1168
1168
+
1169
1169
+
[[package]]
1170
1170
+
name = "windows-future"
1171
1171
+
version = "0.2.1"
1172
1172
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1173
1173
+
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
1174
1174
+
dependencies = [
1175
1175
+
"windows-core",
1176
1176
+
"windows-link 0.1.3",
1177
1177
+
"windows-threading",
1178
1178
+
]
1179
1179
+
1180
1180
+
[[package]]
1181
1181
+
name = "windows-implement"
1182
1182
+
version = "0.60.2"
1183
1183
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1184
1184
+
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
1185
1185
+
dependencies = [
1186
1186
+
"proc-macro2",
1187
1187
+
"quote",
1188
1188
+
"syn",
1189
1189
+
]
1190
1190
+
1191
1191
+
[[package]]
1192
1192
+
name = "windows-interface"
1193
1193
+
version = "0.59.3"
1194
1194
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1195
1195
+
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
1196
1196
+
dependencies = [
1197
1197
+
"proc-macro2",
1198
1198
+
"quote",
1199
1199
+
"syn",
1200
1200
+
]
1201
1201
+
1202
1202
+
[[package]]
1203
1203
+
name = "windows-link"
1204
1204
+
version = "0.1.3"
1205
1205
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1206
1206
+
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
1207
1207
+
1208
1208
+
[[package]]
1071
1209
name = "windows-link"
1072
1210
version = "0.2.1"
1073
1211
source = "registry+https://github.com/rust-lang/crates.io-index"
1074
1212
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
1075
1213
1076
1214
[[package]]
1215
1215
+
name = "windows-numerics"
1216
1216
+
version = "0.2.0"
1217
1217
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1218
1218
+
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
1219
1219
+
dependencies = [
1220
1220
+
"windows-core",
1221
1221
+
"windows-link 0.1.3",
1222
1222
+
]
1223
1223
+
1224
1224
+
[[package]]
1225
1225
+
name = "windows-result"
1226
1226
+
version = "0.3.4"
1227
1227
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1228
1228
+
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
1229
1229
+
dependencies = [
1230
1230
+
"windows-link 0.1.3",
1231
1231
+
]
1232
1232
+
1233
1233
+
[[package]]
1234
1234
+
name = "windows-strings"
1235
1235
+
version = "0.4.2"
1236
1236
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1237
1237
+
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
1238
1238
+
dependencies = [
1239
1239
+
"windows-link 0.1.3",
1240
1240
+
]
1241
1241
+
1242
1242
+
[[package]]
1077
1243
name = "windows-sys"
1078
1244
version = "0.60.2"
1079
1245
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1088
1254
source = "registry+https://github.com/rust-lang/crates.io-index"
1089
1255
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
1090
1256
dependencies = [
1091
1091
-
"windows-link",
1257
1257
+
"windows-link 0.2.1",
1092
1258
]
1093
1259
1094
1260
[[package]]
···
1097
1263
source = "registry+https://github.com/rust-lang/crates.io-index"
1098
1264
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
1099
1265
dependencies = [
1100
1100
-
"windows-link",
1266
1266
+
"windows-link 0.2.1",
1101
1267
"windows_aarch64_gnullvm",
1102
1268
"windows_aarch64_msvc",
1103
1269
"windows_i686_gnu",
···
1106
1272
"windows_x86_64_gnu",
1107
1273
"windows_x86_64_gnullvm",
1108
1274
"windows_x86_64_msvc",
1275
1275
+
]
1276
1276
+
1277
1277
+
[[package]]
1278
1278
+
name = "windows-threading"
1279
1279
+
version = "0.1.0"
1280
1280
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1281
1281
+
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
1282
1282
+
dependencies = [
1283
1283
+
"windows-link 0.1.3",
1109
1284
]
1110
1285
1111
1286
[[package]]
···
1170
1345
"futures-util",
1171
1346
"serde",
1172
1347
"serde_json",
1348
1348
+
"sysinfo",
1173
1349
"tokio",
1174
1350
"tokio-tungstenite",
1175
1351
"tracing",
+1
worker-plane/worker-manager/Cargo.toml
···
8
8
futures-util = "0.3"
9
9
serde = { version = "1.0", features = ["derive"] }
10
10
serde_json = "1.0"
11
11
+
sysinfo = "0.37.2"
11
12
tokio = { version = "1", features = ["full"] }
12
13
tokio-tungstenite = { version = "0.21", features = ["native-tls"] }
13
14
tracing = "0.1"
+75
-9
worker-plane/worker-manager/src/main.rs
···
3
3
use serde::{Deserialize, Serialize};
4
4
use std::env;
5
5
use std::time::Duration;
6
6
+
use sysinfo::{Disks, System};
6
7
use tokio_tungstenite::{connect_async, tungstenite::Message};
7
8
use tracing::{error, info, instrument};
8
9
use tracing_subscriber::FmtSubscriber;
···
36
37
BidResponse(Bid),
37
38
}
38
39
40
40
+
fn get_system_resources() -> (u32, u32, u32) {
41
41
+
let mut sys = System::new();
42
42
+
sys.refresh_cpu_all();
43
43
+
sys.refresh_memory();
44
44
+
45
45
+
let cpu_cores = sys.cpus().len() as u32;
46
46
+
let available_ram_mb = (sys.available_memory() / (1024 * 1024)) as u32;
47
47
+
let available_storage_mb: u32;
48
48
+
49
49
+
let disks = Disks::new_with_refreshed_list();
50
50
+
51
51
+
let exe_path = std::env::current_exe().unwrap_or_else(|_| std::path::PathBuf::from("/"));
52
52
+
53
53
+
let mut best_disk_mount: Option<&std::path::Path> = None;
54
54
+
let mut best_disk_space: u64 = 0;
55
55
+
56
56
+
for disk in disks.iter() {
57
57
+
let mount_point = disk.mount_point();
58
58
+
if exe_path.starts_with(mount_point) {
59
59
+
if best_disk_mount.is_none()
60
60
+
|| mount_point.as_os_str().len() > best_disk_mount.unwrap().as_os_str().len()
61
61
+
{
62
62
+
best_disk_mount = Some(mount_point);
63
63
+
best_disk_space = disk.available_space();
64
64
+
}
65
65
+
}
66
66
+
}
67
67
+
68
68
+
if best_disk_mount.is_some() {
69
69
+
available_storage_mb = (best_disk_space / (1024 * 1024)) as u32;
70
70
+
} else {
71
71
+
let mut total_space: u64 = 0;
72
72
+
for disk in disks.iter() {
73
73
+
match disk.kind() {
74
74
+
sysinfo::DiskKind::HDD | sysinfo::DiskKind::SSD => {
75
75
+
total_space += disk.available_space();
76
76
+
}
77
77
+
_ => {}
78
78
+
}
79
79
+
}
80
80
+
if total_space == 0 {
81
81
+
for disk in disks.iter() {
82
82
+
total_space += disk.available_space();
83
83
+
}
84
84
+
}
85
85
+
available_storage_mb = (total_space / (1024 * 1024)) as u32;
86
86
+
}
87
87
+
88
88
+
(cpu_cores, available_ram_mb, available_storage_mb)
89
89
+
}
90
90
+
91
91
+
async fn spin_up_job(job: Job) {
92
92
+
info!("Spinning up job: {}", job.id);
93
93
+
tokio::time::sleep(Duration::from_secs(5)).await;
94
94
+
info!("Job {} completed. Payload: {}", job.id, job.payload);
95
95
+
}
96
96
+
39
97
#[tokio::main]
40
98
#[instrument]
41
99
async fn main() {
···
44
102
.with_max_level(tracing::Level::INFO)
45
103
.init();
46
104
47
47
-
let server_url = env::var("CONTROL_PLANE_URL")
48
48
-
.unwrap_or_else(|_| "ws://127.0.0.1:8080".to_string());
49
49
-
105
105
+
let server_url =
106
106
+
env::var("CONTROL_PLANE_URL").unwrap_or_else(|_| "ws://127.0.0.1:8080".to_string());
107
107
+
50
108
info!("Attempting to connect to job board at {}", server_url);
51
109
52
110
let url = Url::parse(&server_url).expect("Failed to parse server URL");
···
64
122
Ok(server_msg) => match server_msg {
65
123
ServerMessage::PingForBids { job_id } => {
66
124
info!("Received bid request for job_id: {}", job_id);
125
125
+
let (cpu, ram, storage) = get_system_resources();
67
126
let bid = Bid {
68
127
job_id: job_id.clone(),
69
69
-
available_cpu_cores: 8,
70
70
-
available_ram_mb: 16384,
71
71
-
available_storage_mb: 51200,
128
128
+
available_cpu_cores: cpu,
129
129
+
available_ram_mb: ram,
130
130
+
available_storage_mb: storage,
72
131
};
73
132
let response_msg = WorkerMessage::BidResponse(bid);
74
133
let response_json = serde_json::to_string(&response_msg)
75
134
.expect("Failed to serialize bid response");
76
135
77
77
-
if let Err(e) = write.send(Message::Text(response_json.clone())).await {
136
136
+
if let Err(e) =
137
137
+
write.send(Message::Text(response_json.clone())).await
138
138
+
{
78
139
error!("Failed to send bid response: {}", e);
79
140
break;
80
141
}
81
142
info!("Sent bid for job_id: {}", job_id);
82
143
}
83
144
ServerMessage::AssignJob { job } => {
84
84
-
info!("Won bid! Assigned job: {:?}", job);
145
145
+
info!("Won bid! Assigned job: {}", job.id);
146
146
+
tokio::spawn(spin_up_job(job));
85
147
}
86
148
ServerMessage::Acknowledge => {
87
149
info!("Received Acknowledge from server.");
88
150
}
89
151
},
90
152
Err(e) => {
91
91
-
error!("Failed to deserialize server message: {}. Raw text: {}", e, text);
153
153
+
error!(
154
154
+
"Failed to deserialize server message: {}. Raw text: {}",
155
155
+
e, text
156
156
+
);
92
157
}
93
158
}
94
159
}
···
112
177
tokio::time::sleep(Duration::from_secs(5)).await;
113
178
}
114
179
}
180
180
+