Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
wip(backend): rename CatalogExecutionStatus table and struct into Cat…
Browse files Browse the repository at this point in the history
…alogRun
  • Loading branch information
evoxmusic committed Jan 6, 2024
1 parent f560bad commit 8618079
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
8 changes: 4 additions & 4 deletions backend/db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
10 changes: 5 additions & 5 deletions backend/src/catalog/controllers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<Arc<sqlx::PgPool>>,
Path((catalog_slug, service_slug)): Path<(String, String)>,
) -> (StatusCode, Json<ResultsResponse<CatalogExecutionStatusJson>>) {
match database::list_catalog_execution_statuses(&pg_pool, &catalog_slug, &service_slug).await {
) -> (StatusCode, Json<ResultsResponse<CatalogRunJson>>) {
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() }))
}
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions backend/src/catalog/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -40,7 +40,7 @@ pub struct TaskPayload {

pub async fn background_worker(mut rx: Receiver<BackgroundWorkerTask>, pg_pool: Arc<Pool<Postgres>>) {
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,
Expand All @@ -67,7 +67,7 @@ pub async fn background_worker(mut rx: Receiver<BackgroundWorkerTask>, 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,
Expand All @@ -89,7 +89,7 @@ pub async fn background_worker(mut rx: Receiver<BackgroundWorkerTask>, 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,
Expand Down
34 changes: 17 additions & 17 deletions backend/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -71,16 +71,16 @@ pub async fn init_database(pg_pool: &Pool<Postgres>) -> Result<(), QError> {
Ok(())
}

pub async fn list_catalog_execution_statuses(
pub async fn list_catalog_runs(
pg_pool: &Pool<Postgres>,
catalog_slug: &str,
service_slug: &str,
) -> Result<Vec<CatalogExecutionStatus>, QError> {
) -> Result<Vec<CatalogRun>, 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
"#
)
Expand All @@ -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<Postgres>,
catalog_slug: &str,
service_slug: &str,
status: Status,
input_payload: &serde_json::Value,
tasks: &serde_json::Value,
) -> Result<CatalogExecutionStatus, QError> {
) -> Result<CatalogRun, QError> {
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 *
"#
Expand All @@ -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<Postgres>,
id: &str,
status: Status,
tasks: &serde_json::Value,
) -> Result<CatalogExecutionStatus, QError> {
) -> Result<CatalogRun, QError> {
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 *
Expand Down
5 changes: 3 additions & 2 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function SelfServiceTabService({catalogSlug, services}: Props) {

if (services.length === 0) {
return <div className="my-5">
<EmptyState text="No Fields" subText="This service has no fields."/>
<EmptyState text="No Services" subText="This catalog has no services."/>
</div>
}

Expand Down

0 comments on commit 8618079

Please sign in to comment.