Skip to content

Commit 4cf84d9

Browse files
committed
update local branch and fix conflicts
Signed-off-by: AidCheng <cn.aiden.cheng@gmail.com>
2 parents 7d88252 + 8bbb778 commit 4cf84d9

11 files changed

Lines changed: 211 additions & 151 deletions

File tree

ceres/src/build_trigger/dispatcher.rs

Lines changed: 59 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::sync::Arc;
22

3-
use bellatrix::{Bellatrix, orion_client::OrionBuildRequest};
3+
use bellatrix::{
4+
Bellatrix,
5+
orion_client::{BuildInfo, OrionBuildRequest},
6+
};
47
use common::errors::MegaError;
58
use jupiter::storage::Storage;
69

@@ -17,91 +20,77 @@ impl BuildDispatcher {
1720
Self { storage, bellatrix }
1821
}
1922

20-
/// Dispatch a build trigger.
21-
///
22-
/// This method:
23-
/// 1. Persists the trigger to the database
24-
/// 2. Sends the build request to Bellatrix/Orion asynchronously
25-
///
26-
/// Returns the ID of the created trigger record.
2723
pub async fn dispatch(&self, trigger: BuildTrigger) -> Result<i64, MegaError> {
2824
let trigger_payload = serde_json::to_value(&trigger.payload).map_err(|e| {
2925
tracing::error!("Failed to serialize payload: {}", e);
3026
MegaError::Other(format!("Failed to serialize payload: {}", e))
3127
})?;
3228

29+
// Determine task_id based on whether build system is enabled
30+
let task_id: Option<uuid::Uuid> = if self.bellatrix.enable_build() {
31+
// Extract data from payload using pattern matching
32+
let (cl_link, repo, builds_json, cl_id) = match &trigger.payload {
33+
BuildTriggerPayload::GitPush(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
34+
BuildTriggerPayload::Manual(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
35+
BuildTriggerPayload::Retry(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
36+
BuildTriggerPayload::Webhook(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
37+
BuildTriggerPayload::Schedule(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
38+
BuildTriggerPayload::WebEdit(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
39+
};
40+
41+
let builds: Vec<SerializableBuildInfo> = serde_json::from_value(builds_json.clone())
42+
.map_err(|e| {
43+
tracing::error!("Failed to deserialize builds from payload: {}", e);
44+
MegaError::Other(format!("Failed to deserialize builds from payload: {}", e))
45+
})?;
46+
47+
let bellatrix_builds: Vec<BuildInfo> = builds
48+
.into_iter()
49+
.map(|info| BuildInfo {
50+
changes: info.changes.into_iter().map(|s| s.into()).collect(),
51+
})
52+
.collect();
53+
54+
let req = OrionBuildRequest {
55+
cl_link: cl_link.to_string(),
56+
mount_path: repo.to_string(),
57+
cl: cl_id.unwrap_or(0),
58+
builds: bellatrix_builds,
59+
};
60+
61+
let task_id_str = self.bellatrix.on_post_receive(req).await.map_err(|e| {
62+
tracing::error!("Failed to dispatch build to Bellatrix: {}", e);
63+
MegaError::Other(format!("Failed to dispatch build to Bellatrix: {}", e))
64+
})?;
65+
66+
let task_uuid = uuid::Uuid::parse_str(&task_id_str).map_err(|e| {
67+
tracing::error!("Invalid task_id format '{}': {}", task_id_str, e);
68+
MegaError::Other(format!("Invalid task_id format '{}': {}", task_id_str, e))
69+
})?;
70+
71+
Some(task_uuid)
72+
} else {
73+
tracing::info!("BuildDispatcher: Build system disabled, skipping Orion call");
74+
None
75+
};
76+
77+
// Insert trigger record with task_id (complete record in one operation)
3378
let db_record = self
3479
.storage
3580
.build_trigger_storage()
3681
.insert(
3782
trigger.trigger_type.to_string(),
3883
trigger.trigger_source.to_string(),
3984
trigger_payload,
85+
task_id,
4086
)
4187
.await?;
4288

43-
// Persist to database
44-
tracing::info!("BuildDispatcher: Persisted trigger ID: {}", db_record.id);
45-
46-
if !self.bellatrix.enable_build() {
47-
tracing::info!("BuildDispatcher: Completed (build system disabled)");
48-
return Ok(db_record.id);
49-
}
50-
51-
// Extract data from payload using pattern matching
52-
let (cl_link, repo, builds_json, cl_id) = match &trigger.payload {
53-
BuildTriggerPayload::GitPush(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
54-
BuildTriggerPayload::Manual(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
55-
BuildTriggerPayload::Retry(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
56-
BuildTriggerPayload::Webhook(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
57-
BuildTriggerPayload::Schedule(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
58-
BuildTriggerPayload::WebEdit(p) => (&p.cl_link, &p.repo, &p.builds, p.cl_id),
59-
};
60-
61-
let builds: Vec<SerializableBuildInfo> = serde_json::from_value(builds_json.clone())
62-
.map_err(|e| {
63-
tracing::error!("Failed to deserialize builds from payload: {}", e);
64-
MegaError::Other(format!("Failed to deserialize builds from payload: {}", e))
65-
})?;
66-
67-
let bellatrix_builds: Vec<bellatrix::orion_client::BuildInfo> = builds
68-
.into_iter()
69-
.enumerate()
70-
.map(|(idx, info)| {
71-
tracing::debug!(" Build [{}]: {} change(s)", idx + 1, info.changes.len());
72-
bellatrix::orion_client::BuildInfo {
73-
changes: info.changes.into_iter().map(|s| s.into()).collect(),
74-
}
75-
})
76-
.collect();
77-
78-
let req = OrionBuildRequest {
79-
cl_link: cl_link.to_string(),
80-
mount_path: repo.to_string(),
81-
cl: cl_id.unwrap_or(0),
82-
builds: bellatrix_builds,
83-
};
84-
85-
// Dispatch asynchronously
86-
let bellatrix = self.bellatrix.clone();
87-
let trigger_id = db_record.id;
88-
tokio::spawn(async move {
89-
match bellatrix.on_post_receive(req).await {
90-
Ok(_) => {
91-
tracing::info!(
92-
"BuildDispatcher: Build request sent to Bellatrix (Trigger ID: {})",
93-
trigger_id
94-
);
95-
}
96-
Err(err) => {
97-
tracing::error!(
98-
"BuildDispatcher: Failed to dispatch build (Trigger ID: {}): {}",
99-
trigger_id,
100-
err
101-
);
102-
}
103-
}
104-
});
89+
tracing::info!(
90+
"BuildDispatcher: Trigger persisted (ID: {}, Task ID: {:?})",
91+
db_record.id,
92+
task_id
93+
);
10594

10695
Ok(db_record.id)
10796
}

ceres/src/pack/monorepo.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,13 +1054,16 @@ impl MonoRepo {
10541054
triggered_by: self.username.clone(),
10551055
};
10561056

1057-
let _trigger_id = BuildTriggerService::handle_git_push_event(
1057+
if let Err(e) = BuildTriggerService::handle_git_push_event(
10581058
self.storage.clone(),
10591059
self.git_object_cache.clone(),
10601060
self.bellatrix.clone(),
10611061
event,
10621062
)
1063-
.await?;
1063+
.await
1064+
{
1065+
tracing::error!("Failed to trigger CI pipeline: {}", e);
1066+
}
10641067
}
10651068

10661069
let check_reg = CheckerRegistry::new(self.storage.clone().into(), self.username());
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use sea_orm::entity::prelude::*;
44
use serde::{Deserialize, Serialize};
55

66
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7-
#[sea_orm(table_name = "targets")]
7+
#[sea_orm(table_name = "build_targets")]
88
pub struct Model {
99
#[sea_orm(primary_key, auto_increment = false)]
1010
pub id: Uuid,
@@ -18,18 +18,18 @@ pub struct Model {
1818
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
1919
pub enum Relation {
2020
#[sea_orm(
21-
belongs_to = "super::tasks::Entity",
21+
belongs_to = "super::orion_tasks::Entity",
2222
from = "Column::TaskId",
23-
to = "super::tasks::Column::Id",
23+
to = "super::orion_tasks::Column::Id",
2424
on_update = "Cascade",
2525
on_delete = "Cascade"
2626
)]
27-
Tasks,
27+
OrionTasks,
2828
}
2929

30-
impl Related<super::tasks::Entity> for Entity {
30+
impl Related<super::orion_tasks::Entity> for Entity {
3131
fn to() -> RelationDef {
32-
Relation::Tasks.def()
32+
Relation::OrionTasks.def()
3333
}
3434
}
3535

jupiter/callisto/src/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ pub mod access_token;
66
pub mod buck_session;
77
pub mod buck_session_file;
88
pub mod build_events;
9+
pub mod build_targets;
910
pub mod build_triggers;
11+
pub mod builds;
1012
pub mod check_result;
1113
pub mod commit_auths;
1214
pub mod dynamic_sidebar;
@@ -42,10 +44,9 @@ pub mod mega_tag;
4244
pub mod mega_tree;
4345
pub mod merge_queue;
4446
pub mod notes;
47+
pub mod orion_tasks;
4548
pub mod path_check_configs;
4649
pub mod reactions;
4750
pub mod sea_orm_active_enums;
4851
pub mod ssh_keys;
49-
pub mod targets;
50-
pub mod tasks;
5152
pub mod vault;
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use sea_orm::entity::prelude::*;
44
use serde::{Deserialize, Serialize};
55

66
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7-
#[sea_orm(table_name = "tasks")]
7+
#[sea_orm(table_name = "orion_tasks")]
88
pub struct Model {
99
#[sea_orm(primary_key, auto_increment = false)]
1010
pub id: Uuid,
@@ -19,8 +19,8 @@ pub struct Model {
1919
pub enum Relation {
2020
#[sea_orm(has_many = "super::build_events::Entity")]
2121
BuildEvents,
22-
#[sea_orm(has_many = "super::targets::Entity")]
23-
Targets,
22+
#[sea_orm(has_many = "super::build_targets::Entity")]
23+
BuildTargets,
2424
}
2525

2626
impl Related<super::build_events::Entity> for Entity {
@@ -29,9 +29,9 @@ impl Related<super::build_events::Entity> for Entity {
2929
}
3030
}
3131

32-
impl Related<super::targets::Entity> for Entity {
32+
impl Related<super::build_targets::Entity> for Entity {
3333
fn to() -> RelationDef {
34-
Relation::Targets.def()
34+
Relation::BuildTargets.def()
3535
}
3636
}
3737

jupiter/callisto/src/prelude.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
33
pub use super::{
44
access_token::Entity as AccessToken, buck_session::Entity as BuckSession,
5-
buck_session_file::Entity as BuckSessionFile, builds::Entity as Builds,
6-
check_result::Entity as CheckResult, commit_auths::Entity as CommitAuths,
7-
dynamic_sidebar::Entity as DynamicSidebar, git_blob::Entity as GitBlob,
8-
git_commit::Entity as GitCommit, git_issue::Entity as GitIssue, git_pr::Entity as GitPr,
9-
git_repo::Entity as GitRepo, git_tag::Entity as GitTag, git_tree::Entity as GitTree,
10-
gpg_key::Entity as GpgKey, import_refs::Entity as ImportRefs,
5+
buck_session_file::Entity as BuckSessionFile, build_events::Entity as BuildEvents,
6+
build_targets::Entity as BuildTargets, build_triggers::Entity as BuildTriggers,
7+
builds::Entity as Builds, check_result::Entity as CheckResult,
8+
commit_auths::Entity as CommitAuths, dynamic_sidebar::Entity as DynamicSidebar,
9+
git_blob::Entity as GitBlob, git_commit::Entity as GitCommit, git_issue::Entity as GitIssue,
10+
git_pr::Entity as GitPr, git_repo::Entity as GitRepo, git_tag::Entity as GitTag,
11+
git_tree::Entity as GitTree, gpg_key::Entity as GpgKey, import_refs::Entity as ImportRefs,
1112
issue_cl_references::Entity as IssueClReferences, item_assignees::Entity as ItemAssignees,
1213
item_labels::Entity as ItemLabels, label::Entity as Label, lfs_locks::Entity as LfsLocks,
1314
lfs_objects::Entity as LfsObjects, mega_blob::Entity as MegaBlob, mega_cl::Entity as MegaCl,
@@ -18,7 +19,7 @@ pub use super::{
1819
mega_code_review_thread::Entity as MegaCodeReviewThread, mega_commit::Entity as MegaCommit,
1920
mega_conversation::Entity as MegaConversation, mega_issue::Entity as MegaIssue,
2021
mega_refs::Entity as MegaRefs, mega_tag::Entity as MegaTag, mega_tree::Entity as MegaTree,
21-
merge_queue::Entity as MergeQueue, notes::Entity as Notes,
22+
merge_queue::Entity as MergeQueue, notes::Entity as Notes, orion_tasks::Entity as OrionTasks,
2223
path_check_configs::Entity as PathCheckConfigs, reactions::Entity as Reactions,
23-
ssh_keys::Entity as SshKeys, tasks::Entity as Tasks, vault::Entity as Vault,
24+
ssh_keys::Entity as SshKeys, vault::Entity as Vault,
2425
};

0 commit comments

Comments
 (0)