Skip to content

Commit dc1150b

Browse files
committed
feat: some new api frame
Signed-off-by: Wangyan <topshihun@foxmail.com>
1 parent 75f64ee commit dc1150b

File tree

6 files changed

+252
-2
lines changed

6 files changed

+252
-2
lines changed

orion-server/src/api.rs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ pub fn routers() -> Router<AppState> {
118118
)
119119
.route("/retry-build", post(build_retry_handler))
120120
.route("/v2/health", get(health_check_handler))
121+
.route("/v2/task-retry/{id}", post(task_retry_handler))
122+
.route("/v2/task/{cl}", get(task_get_handler))
123+
.route("/v2/build-event/{task-id}", get(build_event_get_handler))
124+
.route("/v2/target/{task-id}", get(target_get_handler))
121125
}
122126

123127
/// Start queue management background task (event-driven + periodic cleanup)
@@ -1867,6 +1871,129 @@ async fn immediate_work(
18671871
}
18681872
}
18691873

1874+
#[derive(ToSchema, Serialize)]
1875+
pub struct MessageResponse {
1876+
pub message: String,
1877+
}
1878+
1879+
#[derive(ToSchema, Serialize)]
1880+
pub struct BuildEventDTO {
1881+
pub id: String,
1882+
pub task_id: String,
1883+
pub retry_count: i32,
1884+
pub exit_code: Option<i32>,
1885+
pub log: Option<String>,
1886+
pub log_output_file: String,
1887+
pub start_at: String,
1888+
pub end_at: Option<String>,
1889+
}
1890+
1891+
#[derive(ToSchema, Serialize)]
1892+
pub struct OrionTaskDTO {
1893+
pub id: String,
1894+
pub changes: String,
1895+
pub repo_name: String,
1896+
pub cl: String,
1897+
pub created_at: String,
1898+
}
1899+
1900+
#[derive(ToSchema, Serialize)]
1901+
pub struct BuildTargetDTO {
1902+
pub id: String,
1903+
pub task_id: String,
1904+
pub path: String,
1905+
pub target_state: String,
1906+
}
1907+
1908+
#[utoipa::path(
1909+
post,
1910+
path = "/v2/task-retry/{id}",
1911+
params(("id" = String, description = "Task ID to retry task")),
1912+
responses(
1913+
(status = 200, description = "Inserted queque the task", body = MessageResponse),
1914+
(status = 400, description = "ID format error", body = MessageResponse),
1915+
(status = 404, description = "Not found this task ID", body = MessageResponse),
1916+
)
1917+
)]
1918+
pub async fn task_retry_handler(
1919+
State(_state): State<AppState>,
1920+
Path(_id): Path<String>,
1921+
) -> impl IntoResponse {
1922+
let result_message = MessageResponse {
1923+
message: "todo".to_string(),
1924+
};
1925+
(
1926+
StatusCode::BAD_REQUEST,
1927+
serde_json::to_string(&result_message).unwrap(),
1928+
)
1929+
}
1930+
1931+
#[utoipa::path(
1932+
get,
1933+
path = "v2/task/{cl}",
1934+
params(("cl" = String, Path, description = "cl")),
1935+
responses(
1936+
(status = 200, description = "Get task successfully", body = OrionTaskDTO),
1937+
(status = 404, description = "Not found task", body = MessageResponse),
1938+
)
1939+
)]
1940+
pub async fn task_get_handler(
1941+
State(_state): State<AppState>,
1942+
Path(_cl): Path<String>,
1943+
) -> impl IntoResponse {
1944+
let result_message = MessageResponse {
1945+
message: "todo".to_string(),
1946+
};
1947+
(
1948+
StatusCode::NOT_IMPLEMENTED,
1949+
serde_json::to_string(&result_message).unwrap(),
1950+
)
1951+
}
1952+
1953+
#[utoipa::path(
1954+
get,
1955+
path = "v2/build-event/{task-id}",
1956+
params(("task-id" = String, Path, description = "Task ID")),
1957+
responses(
1958+
(status = 200, description = "Get build event successfully", body = BuildEventDTO),
1959+
(status = 404, description = "Not found task", body = MessageResponse),
1960+
)
1961+
)]
1962+
pub async fn build_event_get_handler(
1963+
State(_state): State<AppState>,
1964+
Path(_cl): Path<String>,
1965+
) -> impl IntoResponse {
1966+
let result_message = MessageResponse {
1967+
message: "todo".to_string(),
1968+
};
1969+
(
1970+
StatusCode::NOT_IMPLEMENTED,
1971+
serde_json::to_string(&result_message).unwrap(),
1972+
)
1973+
}
1974+
1975+
#[utoipa::path(
1976+
get,
1977+
path = "v2/target/{task-id}",
1978+
params(("task-id" = String, Path, description = "Task ID")),
1979+
responses(
1980+
(status = 200, description = "Get target successfully", body = BuildTargetDTO),
1981+
(status = 404, description = "Not found task", body = MessageResponse),
1982+
)
1983+
)]
1984+
pub async fn target_get_handler(
1985+
State(_state): State<AppState>,
1986+
Path(_task_id): Path<String>,
1987+
) -> impl IntoResponse {
1988+
let result_message = MessageResponse {
1989+
message: "todo".to_string(),
1990+
};
1991+
(
1992+
StatusCode::NOT_IMPLEMENTED,
1993+
serde_json::to_string(&result_message).unwrap(),
1994+
)
1995+
}
1996+
18701997
#[cfg(test)]
18711998
mod tests {
18721999
/// Test random number generation for worker selection
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "build_events")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: Uuid,
11+
pub task_id: Uuid,
12+
pub retry_count: i32,
13+
pub exit_code: Option<i32>,
14+
pub log: Option<String>,
15+
pub log_output_file: String,
16+
pub start_at: DateTimeWithTimeZone,
17+
pub end_at: Option<DateTimeWithTimeZone>,
18+
}
19+
20+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
21+
pub enum Relation {
22+
#[sea_orm(
23+
belongs_to = "super::orion_tasks::Entity",
24+
from = "Column::TaskId",
25+
to = "super::orion_tasks::Column::Id",
26+
on_update = "Cascade",
27+
on_delete = "Cascade"
28+
)]
29+
OrionTasks,
30+
}
31+
32+
impl Related<super::orion_tasks::Entity> for Entity {
33+
fn to() -> RelationDef {
34+
Relation::OrionTasks.def()
35+
}
36+
}
37+
38+
impl ActiveModelBehavior for ActiveModel {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "build_targets")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: Uuid,
11+
pub task_id: Uuid,
12+
#[sea_orm(column_type = "JsonBinary")]
13+
pub path: Json,
14+
#[sea_orm(column_type = "Text")]
15+
pub target_state: String,
16+
}
17+
18+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
19+
pub enum Relation {
20+
#[sea_orm(
21+
belongs_to = "super::orion_tasks::Entity",
22+
from = "Column::TaskId",
23+
to = "super::orion_tasks::Column::Id",
24+
on_update = "Cascade",
25+
on_delete = "Cascade"
26+
)]
27+
OrionTasks,
28+
}
29+
30+
impl Related<super::orion_tasks::Entity> for Entity {
31+
fn to() -> RelationDef {
32+
Relation::OrionTasks.def()
33+
}
34+
}
35+
36+
impl ActiveModelBehavior for ActiveModel {}

orion-server/src/model/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// pub mod build_events;
2+
// pub mod build_targets;
13
pub mod builds;
4+
// pub mod orion_tasks;
25
pub mod targets;
36
pub mod tasks;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "orion_tasks")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: Uuid,
11+
#[sea_orm(column_type = "JsonBinary")]
12+
pub changes: Json,
13+
pub repo_name: String,
14+
pub cl: String,
15+
pub created_at: DateTimeWithTimeZone,
16+
}
17+
18+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
19+
pub enum Relation {
20+
#[sea_orm(has_many = "super::build_events::Entity")]
21+
BuildEvents,
22+
#[sea_orm(has_many = "super::build_targets::Entity")]
23+
BuildTargets,
24+
}
25+
26+
impl Related<super::build_events::Entity> for Entity {
27+
fn to() -> RelationDef {
28+
Relation::BuildEvents.def()
29+
}
30+
}
31+
32+
impl Related<super::build_targets::Entity> for Entity {
33+
fn to() -> RelationDef {
34+
Relation::BuildTargets.def()
35+
}
36+
}
37+
38+
impl ActiveModelBehavior for ActiveModel {}

orion-server/src/server.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ use crate::{
4343
api::get_orion_clients_info,
4444
api::get_orion_client_status_by_id,
4545
api::build_retry_handler,
46-
api::health_check_handler
46+
api::health_check_handler,
47+
api::task_retry_handler,
48+
api::task_get_handler,
49+
api::build_event_get_handler,
50+
api::target_get_handler,
4751
),
4852
components(
4953
schemas(
@@ -64,7 +68,11 @@ use crate::{
6468
api::CoreWorkerStatus,
6569
api::OrionClientQuery,
6670
crate::model::targets::TargetState,
67-
TaskPhase
71+
TaskPhase,
72+
api::MessageResponse,
73+
api::BuildEventDTO,
74+
api::OrionTaskDTO,
75+
api::BuildTargetDTO,
6876
)
6977
),
7078
tags(

0 commit comments

Comments
 (0)