diff --git a/ceres/src/api_service/mono_api_service.rs b/ceres/src/api_service/mono_api_service.rs index 9ca06e8c9..62fcddee7 100644 --- a/ceres/src/api_service/mono_api_service.rs +++ b/ceres/src/api_service/mono_api_service.rs @@ -45,6 +45,7 @@ use callisto::sea_orm_active_enums::ConvTypeEnum; use callisto::{mega_blob, mega_mr, mega_tree, raw_blob}; use common::errors::MegaError; use common::model::Pagination; + use jupiter::storage::base_storage::StorageConnector; use jupiter::storage::Storage; use jupiter::utils::converter::generate_git_keep_with_timestamp; @@ -53,6 +54,7 @@ use mercury::hash::SHA1; use mercury::internal::object::blob::Blob; use mercury::internal::object::commit::Commit; use mercury::internal::object::tree::{Tree, TreeItem, TreeItemMode}; + use neptune::model::diff_model::DiffItem; use neptune::neptune_engine::Diff; @@ -60,6 +62,7 @@ use crate::api_service::ApiHandler; use crate::model::git::CreateFileInfo; use crate::model::mr::MrDiffFile; + #[derive(Clone)] pub struct MonoApiService { pub storage: Storage, @@ -493,6 +496,7 @@ impl MonoApiService { } } + if !failed_hashes.is_empty() { tracing::warn!( "Failed to fetch {} blob(s): {:?}", @@ -523,6 +527,7 @@ impl MonoApiService { .await; Ok(diff_output) + } fn collect_page_blobs( @@ -629,6 +634,7 @@ impl MonoApiService { #[cfg(test)] mod test { use super::*; + use crate::model::mr::MrDiffFile; use mercury::hash::SHA1; use std::path::PathBuf; diff --git a/orion-server/db/schema.sql b/orion-server/db/schema.sql new file mode 100644 index 000000000..362293bc1 --- /dev/null +++ b/orion-server/db/schema.sql @@ -0,0 +1,15 @@ +-- Orion schema (no CREATE DATABASE here) +CREATE TABLE IF NOT EXISTS public.builds ( + build_id UUID PRIMARY KEY, + output_file TEXT NOT NULL, + exit_code INTEGER, + start_at TIMESTAMPTZ NOT NULL, + end_at TIMESTAMPTZ, + repo_name TEXT NOT NULL, + target TEXT NOT NULL, + arguments TEXT NOT NULL, + mr TEXT NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_builds_mr ON public.builds (mr); +CREATE INDEX IF NOT EXISTS idx_builds_start_at ON public.builds (start_at); diff --git a/orion-server/docker-compose.yml b/orion-server/docker-compose.yml index 6b60e5e97..d699fca51 100644 --- a/orion-server/docker-compose.yml +++ b/orion-server/docker-compose.yml @@ -15,6 +15,8 @@ services: depends_on: db: condition: service_healthy + db-init: + condition: service_completed_successfully restart: unless-stopped db: @@ -35,5 +37,34 @@ services: retries: 5 restart: unless-stopped + db-init: + image: postgres:15 + container_name: orion-db-init + depends_on: + db: + condition: service_healthy + environment: + PGPASSWORD: postgres + volumes: + - ./db/schema.sql:/schema.sql:ro + entrypoint: ["sh", "-lc"] + command: | + set -euo pipefail + echo "[db-init] Waiting for Postgres to be ready..." + until pg_isready -h db -p 5432 -U postgres >/dev/null 2>&1; do echo -n "."; sleep 1; done + echo " OK" + + if ! psql -h db -p 5432 -U postgres -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='orion'" | grep -q 1; then + echo "[db-init] Creating database 'orion'..." + psql -h db -p 5432 -U postgres -d postgres -v ON_ERROR_STOP=1 -c "CREATE DATABASE orion" + else + echo "[db-init] Database 'orion' already exists." + fi + + echo "[db-init] Applying schema to 'orion'..." + psql -h db -p 5432 -U postgres -d orion -v ON_ERROR_STOP=1 -f /schema.sql + echo "[db-init] Schema applied." + restart: "no" + volumes: pgdata: \ No newline at end of file diff --git a/orion-server/src/api.rs b/orion-server/src/api.rs index b2f6a42c4..1868ecd12 100644 --- a/orion-server/src/api.rs +++ b/orion-server/src/api.rs @@ -92,7 +92,7 @@ pub fn routers() -> Router { get(task_output_segment_handler), ) .route("/mr-task/{mr}", get(task_query_by_mr)) - .route("/tasks", get(tasks_handler)) + .route("/tasks/{mr}", get(tasks_handler)) .route("/queue-stats", get(queue_stats_handler)) } @@ -812,6 +812,9 @@ impl TaskInfoDTO { #[utoipa::path( get, path = "/tasks", + params( + ("mr" = String, Path, description = "MR number to filter tasks by") + ), responses( (status = 200, description = "All tasks with their current status", body = [TaskInfoDTO]), (status = 500, description = "Internal error", body = serde_json::Value) @@ -820,10 +823,11 @@ impl TaskInfoDTO { /// Return all tasks with their current status (combining /mr-task and /task-status logic) pub async fn tasks_handler( State(state): State, + Path(mr): Path, ) -> Result>, (StatusCode, Json)> { let db = &state.conn; let active_builds = state.scheduler.active_builds.clone(); - match builds::Entity::find().all(db).await { + match builds::Entity::find().filter(builds::Column::Mr.eq(mr)).all(db).await { Ok(models) => { let tasks: Vec = models .into_iter() diff --git a/orion-server/src/server.rs b/orion-server/src/server.rs index a72648dc9..f7ee3b53d 100644 --- a/orion-server/src/server.rs +++ b/orion-server/src/server.rs @@ -21,6 +21,7 @@ use utoipa_swagger_ui::SwaggerUi; api::task_output_handler, api::task_output_segment_handler, api::task_query_by_mr, + api::tasks_handler, ), components( schemas( @@ -28,7 +29,9 @@ use utoipa_swagger_ui::SwaggerUi; crate::scheduler::LogSegment, api::TaskStatus, api::TaskStatusEnum, - api::BuildDTO + api::BuildDTO, + api::TaskInfoDTO + ) ), tags( diff --git a/orion/Cargo.toml b/orion/Cargo.toml index 0775c4b46..a39173e71 100644 --- a/orion/Cargo.toml +++ b/orion/Cargo.toml @@ -14,7 +14,7 @@ futures-util = { workspace = true } dashmap = { workspace = true } once_cell = { workspace = true } dotenvy = { workspace = true } -tokio-tungstenite = { workspace = true } +tokio-tungstenite = { workspace = true , features = ["native-tls"]} tungstenite = { workspace = true } serde_json = { workspace = true } -reqwest = { workspace = true, features = ["json"] } +reqwest = { workspace = true, features = ["json", "rustls-tls"] }