Skip to content

Commit e0042c9

Browse files
Merge pull request #9 from Traverse-Research/jasper-bekkers/worker-progress-logging
Jasper bekkers/worker progress logging
2 parents a185dc3 + 30552cb commit e0042c9

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

src/hetzner.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub struct PublicNet {
4343
pub ipv4: Ipv4,
4444
}
4545

46+
#[allow(dead_code)]
4647
#[derive(Debug, Serialize, Deserialize)]
4748
pub struct IpAddress {
4849
pub ip: String,
@@ -87,13 +88,22 @@ struct CreateServerRequest {
8788
#[derive(Debug, Deserialize)]
8889
struct CreateServerResponse {
8990
server: Server,
91+
root_password: Option<String>,
9092
}
9193

94+
/// Result of creating a server, includes the server info and root password
95+
pub struct CreateServerResult {
96+
pub server: Server,
97+
pub root_password: Option<String>,
98+
}
99+
100+
#[allow(dead_code)]
92101
#[derive(Debug, Deserialize)]
93102
struct ErrorResponse {
94103
error: ErrorDetail,
95104
}
96105

106+
#[allow(dead_code)]
97107
#[derive(Debug, Deserialize)]
98108
struct ErrorDetail {
99109
message: String,
@@ -112,7 +122,7 @@ impl HetznerClient {
112122
}
113123
}
114124

115-
pub async fn create_server(&self, config: &ServerConfig) -> Result<Server> {
125+
pub async fn create_server(&self, config: &ServerConfig) -> Result<CreateServerResult> {
116126
let url = format!("{}/servers", HETZNER_API_BASE);
117127

118128
let labels = if config.labels.is_empty() {
@@ -183,7 +193,10 @@ impl HetznerClient {
183193
result.server.name, result.server.id, result.server.public_net.ipv4.ip
184194
);
185195

186-
Ok(result.server)
196+
Ok(CreateServerResult {
197+
server: result.server,
198+
root_password: result.root_password,
199+
})
187200
}
188201

189202
pub async fn delete_server(&self, id: u64) -> Result<()> {
@@ -338,7 +351,9 @@ impl HetznerClient {
338351
#[derive(Debug, Deserialize)]
339352
struct ServerTypesAvailable {
340353
available: Vec<u64>,
354+
#[allow(dead_code)]
341355
available_for_migration: Vec<u64>,
356+
#[allow(dead_code)]
342357
supported: Vec<u64>,
343358
}
344359

@@ -370,6 +385,7 @@ impl HetznerClient {
370385
.collect())
371386
}
372387

388+
#[allow(dead_code)]
373389
pub async fn get_server(&self, id: u64) -> Result<Server> {
374390
let url = format!("{}/servers/{}", HETZNER_API_BASE, id);
375391

@@ -448,6 +464,7 @@ final_message: "FFmpeg worker is ready!"
448464
}
449465

450466
/// Cloud-init config with SSH key access
467+
#[allow(dead_code)]
451468
pub fn worker_cloud_init_with_ssh(
452469
queue_url: &str,
453470
binary_url: &str,
@@ -496,13 +513,19 @@ final_message: "FFmpeg worker is ready!"
496513
)
497514
}
498515

516+
/// Result of provisioning a worker
517+
pub struct ProvisionResult {
518+
pub ip: String,
519+
pub root_password: Option<String>,
520+
}
521+
499522
pub async fn provision_worker(
500523
hetzner_token: &str,
501524
queue_url: &str,
502525
binary_url: &str,
503526
bg_image_url: &str,
504527
name: Option<String>,
505-
) -> Result<String> {
528+
) -> Result<ProvisionResult> {
506529
let client = HetznerClient::new(hetzner_token.to_string());
507530

508531
let name = name.unwrap_or_else(|| {
@@ -520,6 +543,9 @@ pub async fn provision_worker(
520543
..Default::default()
521544
};
522545

523-
let server = client.create_server(&config).await?;
524-
Ok(server.public_net.ipv4.ip)
546+
let result = client.create_server(&config).await?;
547+
Ok(ProvisionResult {
548+
ip: result.server.public_net.ipv4.ip,
549+
root_password: result.root_password,
550+
})
525551
}

src/hetzner_cli.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,18 @@ async fn main() -> Result<()> {
7777
let binary_url = format!("{}/assets/worker", base);
7878
let bg_image_url = format!("{}/assets/gpc-bg.png", base);
7979

80-
let ip = hetzner::provision_worker(
80+
let result = hetzner::provision_worker(
8181
&token,
8282
&queue_url,
8383
&binary_url,
8484
&bg_image_url,
8585
name,
8686
)
8787
.await?;
88-
println!("Worker provisioned at IP: {}", ip);
88+
println!("Worker provisioned at IP: {}", result.ip);
89+
if let Some(password) = result.root_password {
90+
println!("Root password: {}", password);
91+
}
8992
}
9093
Commands::ListServers { token } => {
9194
let client = hetzner::HetznerClient::new(token);

src/jobs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl RemoteLogger {
316316
}
317317

318318
let client = reqwest::Client::new();
319-
let url = format!("{}/jobs/{}/logs", self.queue_url, self.job_id);
319+
let url = format!("{}/api/jobs/{}/logs", self.queue_url, self.job_id);
320320

321321
#[derive(Serialize)]
322322
struct LogsPayload {
@@ -811,7 +811,7 @@ async fn update_job_progress_remote(
811811
let client = reqwest::Client::new();
812812

813813
client
814-
.patch(format!("{}/jobs/{}/progress", queue_url, job_id))
814+
.patch(format!("{}/api/jobs/{}/progress", queue_url, job_id))
815815
.json(&progress)
816816
.send()
817817
.await
@@ -845,7 +845,7 @@ async fn update_job_status_remote(
845845
};
846846

847847
client
848-
.patch(format!("{}/jobs/{}", queue_url, job_id))
848+
.patch(format!("{}/api/jobs/{}", queue_url, job_id))
849849
.json(&update)
850850
.send()
851851
.await

0 commit comments

Comments
 (0)