From 861807914be16e536ec75aebafe8a91ed227fa8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romaric=20Philog=C3=A8ne?= Date: Sat, 6 Jan 2024 21:24:32 +0100 Subject: [PATCH] wip(backend): rename CatalogExecutionStatus table and struct into CatalogRun --- backend/db/schema.sql | 8 ++--- backend/src/catalog/controllers.rs | 10 +++--- backend/src/catalog/services.rs | 8 ++--- backend/src/database.rs | 34 +++++++++---------- backend/src/main.rs | 5 +-- .../self-service/SelfServiceTabService.tsx | 2 +- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/backend/db/schema.sql b/backend/db/schema.sql index 95d7889..0860040 100644 --- a/backend/db/schema.sql +++ b/backend/db/schema.sql @@ -13,8 +13,8 @@ $$ END $$; --- create a new flat table to store catalog execution results -CREATE TABLE IF NOT EXISTS catalog_execution_statuses +-- create a new flat table to store catalog runs +CREATE TABLE IF NOT EXISTS catalog_runs ( id UUID PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, @@ -26,5 +26,5 @@ CREATE TABLE IF NOT EXISTS catalog_execution_statuses tasks JSONB DEFAULT '{}'::jsonb NOT NULL ); -CREATE INDEX IF NOT EXISTS catalog_execution_statuses_catalog_slug_idx ON catalog_execution_statuses (catalog_slug); -CREATE INDEX IF NOT EXISTS catalog_execution_statuses_service_slug_idx ON catalog_execution_statuses (service_slug); +CREATE INDEX IF NOT EXISTS catalog_runs_catalog_slug_idx ON catalog_runs (catalog_slug); +CREATE INDEX IF NOT EXISTS catalog_runs_service_slug_idx ON catalog_runs (service_slug); diff --git a/backend/src/catalog/controllers.rs b/backend/src/catalog/controllers.rs index d4e2438..545503d 100644 --- a/backend/src/catalog/controllers.rs +++ b/backend/src/catalog/controllers.rs @@ -9,7 +9,7 @@ use tracing::error; use crate::catalog::{check_json_payload_against_yaml_config_fields, execute_command, ExecValidateScriptRequest, find_catalog_by_slug, get_catalog_and_service, JobResponse, ResultsResponse}; use crate::catalog::services::BackgroundWorkerTask; use crate::database; -use crate::database::{CatalogExecutionStatusJson, insert_catalog_execution_status, Status}; +use crate::database::{CatalogRunJson, insert_catalog_run, Status}; use crate::yaml_config::{CatalogServiceYamlConfig, CatalogYamlConfig, YamlConfig}; #[debug_handler] @@ -36,11 +36,11 @@ pub async fn list_catalog_services( } #[debug_handler] -pub async fn list_catalog_execution_statuses( +pub async fn list_catalog_runs( Extension(pg_pool): Extension>, Path((catalog_slug, service_slug)): Path<(String, String)>, -) -> (StatusCode, Json>) { - match database::list_catalog_execution_statuses(&pg_pool, &catalog_slug, &service_slug).await { +) -> (StatusCode, Json>) { + match database::list_catalog_runs(&pg_pool, &catalog_slug, &service_slug).await { Ok(catalog_execution_statuses) => { (StatusCode::OK, Json(ResultsResponse { message: None, results: catalog_execution_statuses.iter().map(|x| x.to_json()).collect() })) } @@ -121,7 +121,7 @@ pub async fn exec_catalog_service_post_validate_scripts( }; } - let ces = match insert_catalog_execution_status( + let ces = match insert_catalog_run( &pg_pool, &catalog_slug, &service_slug, diff --git a/backend/src/catalog/services.rs b/backend/src/catalog/services.rs index 94cc68e..608af03 100644 --- a/backend/src/catalog/services.rs +++ b/backend/src/catalog/services.rs @@ -6,7 +6,7 @@ use tokio::sync::mpsc::Receiver; use tracing::error; use crate::catalog::{execute_command, ExecValidateScriptRequest, JobOutputResult}; -use crate::database::{Status, update_catalog_execution_status}; +use crate::database::{Status, update_catalog_run}; use crate::yaml_config::{CatalogServicePostValidateYamlConfig, CatalogServiceYamlConfig}; #[derive(Serialize, Deserialize)] @@ -40,7 +40,7 @@ pub struct TaskPayload { pub async fn background_worker(mut rx: Receiver, pg_pool: Arc>) { while let Some(task) = rx.recv().await { - let r = update_catalog_execution_status( + let r = update_catalog_run( &pg_pool, task.catalog_execution_status_id.as_str(), Status::Running, @@ -67,7 +67,7 @@ pub async fn background_worker(mut rx: Receiver, pg_pool: let _ = tasks.push(task_payload); - let _ = update_catalog_execution_status( + let _ = update_catalog_run( &pg_pool, task.catalog_execution_status_id.as_str(), Status::Failure, @@ -89,7 +89,7 @@ pub async fn background_worker(mut rx: Receiver, pg_pool: let _ = tasks.push(task_payload); - let _ = update_catalog_execution_status( + let _ = update_catalog_run( &pg_pool, task.catalog_execution_status_id.as_str(), Status::Success, diff --git a/backend/src/database.rs b/backend/src/database.rs index fcfeb06..1be32a9 100644 --- a/backend/src/database.rs +++ b/backend/src/database.rs @@ -7,7 +7,7 @@ use sqlx::types::Uuid; use crate::errors::QError; #[derive(sqlx::FromRow)] -pub struct CatalogExecutionStatus { +pub struct CatalogRun { id: Uuid, created_at: chrono::NaiveDateTime, updated_at: chrono::NaiveDateTime, @@ -29,9 +29,9 @@ pub enum Status { Failure, } -impl CatalogExecutionStatus { - pub fn to_json(&self) -> CatalogExecutionStatusJson { - CatalogExecutionStatusJson { +impl CatalogRun { + pub fn to_json(&self) -> CatalogRunJson { + CatalogRunJson { id: self.id.to_string(), created_at: self.created_at.to_string(), updated_at: self.updated_at.to_string(), @@ -49,7 +49,7 @@ impl CatalogExecutionStatus { } #[derive(Serialize, Deserialize, Debug)] -pub struct CatalogExecutionStatusJson { +pub struct CatalogRunJson { pub id: String, pub created_at: String, pub updated_at: String, @@ -71,16 +71,16 @@ pub async fn init_database(pg_pool: &Pool) -> Result<(), QError> { Ok(()) } -pub async fn list_catalog_execution_statuses( +pub async fn list_catalog_runs( pg_pool: &Pool, catalog_slug: &str, service_slug: &str, -) -> Result, QError> { +) -> Result, QError> { Ok( - sqlx::query_as::<_, CatalogExecutionStatus>( + sqlx::query_as::<_, CatalogRun>( r#" SELECT * - FROM catalog_execution_statuses + FROM catalog_runs WHERE catalog_slug = $1 AND service_slug = $2 "# ) @@ -91,18 +91,18 @@ pub async fn list_catalog_execution_statuses( ) } -pub async fn insert_catalog_execution_status( +pub async fn insert_catalog_run( pg_pool: &Pool, catalog_slug: &str, service_slug: &str, status: Status, input_payload: &serde_json::Value, tasks: &serde_json::Value, -) -> Result { +) -> Result { Ok( - sqlx::query_as::<_, CatalogExecutionStatus>( + sqlx::query_as::<_, CatalogRun>( r#" - INSERT INTO catalog_execution_statuses (catalog_slug, service_slug, status, input_payload, tasks) + INSERT INTO catalog_runs (catalog_slug, service_slug, status, input_payload, tasks) VALUES ($1, $2, $3, $4, $5) RETURNING * "# @@ -117,16 +117,16 @@ pub async fn insert_catalog_execution_status( ) } -pub async fn update_catalog_execution_status( +pub async fn update_catalog_run( pg_pool: &Pool, id: &str, status: Status, tasks: &serde_json::Value, -) -> Result { +) -> Result { Ok( - sqlx::query_as::<_, CatalogExecutionStatus>( + sqlx::query_as::<_, CatalogRun>( r#" - UPDATE catalog_execution_statuses + UPDATE catalog_runs SET status = $1, tasks = $2 WHERE id = $3 RETURNING * diff --git a/backend/src/main.rs b/backend/src/main.rs index 383eecb..f1899f5 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -13,7 +13,7 @@ use tracing::log::warn; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; -use crate::catalog::controllers::{exec_catalog_service_post_validate_scripts, exec_catalog_service_validate_scripts, list_catalog_execution_statuses, list_catalog_services, list_catalogs}; +use crate::catalog::controllers::{exec_catalog_service_post_validate_scripts, exec_catalog_service_validate_scripts, list_catalog_runs, list_catalog_services, list_catalogs}; use crate::catalog::services::BackgroundWorkerTask; use crate::cli::CLI; use crate::database::init_database; @@ -106,9 +106,10 @@ async fn main() { .route("/healthz", get(|| async { "OK" })) .route("/catalogs", get(list_catalogs)) .route("/catalogs/:slug/services", get(list_catalog_services)) + .route("/catalogs/:slug/runs", get(list_catalog_services)) .route("/catalogs/:slug/services/:slug/validate", post(exec_catalog_service_validate_scripts)) .route("/catalogs/:slug/services/:slug/execute", post(exec_catalog_service_post_validate_scripts)) - .route("/catalogs/:slug/services/:slug/status", get(list_catalog_execution_statuses)) + .route("/catalogs/:slug/services/:slug/runs", get(list_catalog_runs)) .layer(Extension(yaml_config)) .layer(Extension(tx)) .layer(Extension(pg_pool)) diff --git a/frontend/src/components/self-service/SelfServiceTabService.tsx b/frontend/src/components/self-service/SelfServiceTabService.tsx index 4e17d66..0845470 100644 --- a/frontend/src/components/self-service/SelfServiceTabService.tsx +++ b/frontend/src/components/self-service/SelfServiceTabService.tsx @@ -28,7 +28,7 @@ export default function SelfServiceTabService({catalogSlug, services}: Props) { if (services.length === 0) { return
- +
}