Skip to content

Commit 7d88252

Browse files
committed
[orion] Replace worker-server commun with WS msg
Signed-off-by: AidCheng <cn.aiden.cheng@gmail.com>
1 parent 33040a1 commit 7d88252

7 files changed

Lines changed: 55 additions & 59 deletions

File tree

jupiter/callisto/src/mega_code_review_thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use sea_orm::entity::prelude::*;
44
use serde::{Deserialize, Serialize};
55

6-
use super::sea_orm_active_enums::{DiffSideEnum, ThreadStatusEnum};
6+
use super::sea_orm_active_enums::{ThreadStatusEnum};
77

88
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
99
#[sea_orm(table_name = "mega_code_review_thread")]

orion-server/src/api.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ async fn immediate_work(
17171717
);
17181718
let build_info = BuildInfo {
17191719
event_payload: event,
1720-
target_id: target.id.to_string(),
1720+
target_id: target.id,
17211721
target_path: target.target_path.clone(),
17221722
changes: req.build.changes.clone(),
17231723
_worker_id: chosen_id.clone(),
@@ -1726,12 +1726,13 @@ async fn immediate_work(
17261726
};
17271727

17281728
// Send build to worker
1729-
let msg = TaskBuildRequest {
1729+
let msg = WSMessage::Task {
17301730
id: build.id.to_string(),
17311731
repo: build.repo.to_string(),
17321732
changes: req.build.changes.clone(),
17331733
cl_link: req.cl_link.to_string(),
17341734
};
1735+
17351736
if let Some(mut worker) = state.scheduler.workers.get_mut(&chosen_id)
17361737
&& worker.sender.send(msg).is_ok()
17371738
{

orion-server/src/scheduler.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ impl TaskScheduler {
270270
}
271271
}
272272

273+
/// Ensure target exists for the given task and target path, return the target model
274+
///
275+
/// Creates a new target if not exists
273276
pub async fn ensure_target(
274277
&self,
275278
task_id: Uuid,
@@ -330,7 +333,7 @@ impl TaskScheduler {
330333

331334
let pending_build_event = PendingBuildEvent {
332335
event_payload: event,
333-
target_id: None,
336+
target_id: target_model.id.into(),
334337
target_path: None,
335338
changes: changes,
336339
created_at: Instant::now(),
@@ -456,7 +459,7 @@ impl TaskScheduler {
456459
id: Set(pending_build_event.build_event_id),
457460
task_id: Set(pending_build_event.task_id),
458461
// target_id: Set(pending_build_event.target_id),
459-
target_id: Set(None),
462+
target_id: Set(Uuid::nil()),
460463
exit_code: Set(None),
461464
start_at: Set(start_at_tz),
462465
end_at: Set(None),
@@ -503,8 +506,7 @@ impl TaskScheduler {
503506
if let Err(e) = targets::update_state(
504507
&self.conn,
505508
//TODO: update target_id here
506-
// pending_task.target_id,
507-
0,
509+
pending_build_event.target_id.unwrap_or_else(|| Uuid::nil()),
508510
TargetState::Building,
509511
Some(start_at_tz),
510512
None,
@@ -533,7 +535,7 @@ impl TaskScheduler {
533535
let _ = targets::update_state(
534536
&self.conn,
535537
// TODO: update target_id here
536-
pending_build_event.target_id,
538+
pending_build_event.target_id.unwrap_or_else(|| Uuid::nil()),
537539
TargetState::Pending,
538540
Some(start_at_tz),
539541
None,

orion/buck/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::{ffi::OsStr, fmt, hash::Hash, str::FromStr};
1515
use parse_display::Display;
1616
use serde::{Deserialize, Serialize};
1717
use td_util::string::InternString;
18-
use utoipa::ToSchema;
1918

2019
use crate::{cells::CellInfo, labels::Labels};
2120

orion/src/api.rs

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use api_model::buck2::{
2-
api::{TaskBuildRequest, TaskBuildResult},
3-
ws::WSMessage,
2+
api::TaskBuildResult, status::Status, types::ProjectRelativePath, ws::WSMessage,
43
};
54
use tokio::sync::mpsc::UnboundedSender;
65
use uuid::Uuid;
@@ -46,7 +45,9 @@ use crate::buck_controller;
4645
/// Immediate acknowledgment that the build task has been queued and started
4746
pub async fn buck_build(
4847
id: Uuid,
49-
req: TaskBuildRequest,
48+
cl_link: String,
49+
repo: String,
50+
changes: Vec<Status<ProjectRelativePath>>,
5051
sender: UnboundedSender<WSMessage>,
5152
) -> TaskBuildResult {
5253
let id_str = id.to_string();
@@ -55,48 +56,43 @@ pub async fn buck_build(
5556
// Spawn background task to handle the actual build process
5657
tokio::spawn(async move {
5758
// Execute the build operation via buck_controller
58-
let build_result = match buck_controller::build(
59-
id_str.clone(),
60-
req.repo,
61-
req.cl_link,
62-
sender.clone(),
63-
req.changes,
64-
)
65-
.await
66-
{
67-
Ok(status) => {
68-
let message = format!(
69-
"Build {}",
70-
if status.success() {
71-
"succeeded"
72-
} else {
73-
"failed"
59+
let build_result =
60+
match buck_controller::build(id_str.clone(), repo, cl_link, sender.clone(), changes)
61+
.await
62+
{
63+
Ok(status) => {
64+
let message = format!(
65+
"Build {}",
66+
if status.success() {
67+
"succeeded"
68+
} else {
69+
"failed"
70+
}
71+
);
72+
tracing::info!(
73+
"[Task {}] {}; Exit code: {:?}",
74+
id_str,
75+
message,
76+
status.code()
77+
);
78+
TaskBuildResult {
79+
success: status.success(),
80+
id: id_str.clone(),
81+
exit_code: status.code(),
82+
message,
7483
}
75-
);
76-
tracing::info!(
77-
"[Task {}] {}; Exit code: {:?}",
78-
id_str,
79-
message,
80-
status.code()
81-
);
82-
TaskBuildResult {
83-
success: status.success(),
84-
id: id_str.clone(),
85-
exit_code: status.code(),
86-
message,
8784
}
88-
}
89-
Err(e) => {
90-
let error_msg = format!("Build execution failed: {e}");
91-
tracing::error!("[Task {}] {}", id_str, error_msg);
92-
TaskBuildResult {
93-
success: false,
94-
id: id_str.clone(),
95-
exit_code: None,
96-
message: error_msg,
85+
Err(e) => {
86+
let error_msg = format!("Build execution failed: {e}");
87+
tracing::error!("[Task {}] {}", id_str, error_msg);
88+
TaskBuildResult {
89+
success: false,
90+
id: id_str.clone(),
91+
exit_code: None,
92+
message: error_msg,
93+
}
9794
}
98-
}
99-
};
95+
};
10096

10197
// Send build completion notification via WebSocket
10298
let complete_msg = WSMessage::TaskBuildComplete {

orion/src/buck_controller.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::{
88

99
use anyhow::anyhow;
1010
use api_model::buck2::{
11-
types::{ProjectRelativePath, Status, TaskPhase},
11+
status::Status,
12+
types::{ProjectRelativePath, TaskPhase},
1213
ws::WSMessage,
1314
};
1415
use once_cell::sync::Lazy;

orion/src/ws.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{ops::ControlFlow, time::Duration};
22

3-
use api_model::buck2::{api::TaskBuildRequest, ws::WSMessage};
3+
use api_model::buck2::ws::WSMessage;
44
use futures_util::{SinkExt, StreamExt};
55
use tokio::{
66
net::TcpStream,
@@ -188,12 +188,9 @@ async fn process_server_message(
188188

189189
let build_result = buck_build(
190190
task_id_uuid,
191-
TaskBuildRequest {
192-
repo,
193-
cl_link,
194-
changes,
195-
None,
196-
},
191+
repo,
192+
cl_link,
193+
changes,
197194
sender.clone(),
198195
)
199196
.await;

0 commit comments

Comments
 (0)