From 61a4f5c10aab8da78c8d1cee218fed43e16c474c Mon Sep 17 00:00:00 2001 From: iamvigneshwars Date: Tue, 9 Apr 2024 14:25:35 +0000 Subject: [PATCH] Autoproc scaling and statistics resolvers --- processed_data/src/graphql/entities.rs | 4 +- processed_data/src/graphql/mod.rs | 77 +++++++++++++++++++------- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/processed_data/src/graphql/entities.rs b/processed_data/src/graphql/entities.rs index 430c553..985d745 100644 --- a/processed_data/src/graphql/entities.rs +++ b/processed_data/src/graphql/entities.rs @@ -74,7 +74,7 @@ impl From for ProcessingJobParameter { /// Represents an auto processed job #[derive(Clone, Debug, PartialEq, SimpleObject)] -#[graphql(name = "AutoProc", unresolvable)] +#[graphql(name = "AutoProc", unresolvable, complex)] pub struct AutoProc { /// An opaque unique identifier for the auto processing pub auto_proc_id: u32, @@ -170,7 +170,7 @@ impl From for AutoProcIntegration { /// Represents and auto processing scaling #[derive(Clone, Debug, PartialEq, SimpleObject)] -#[graphql(name = "AutoProcScaling", unresolvable)] +#[graphql(name = "AutoProcScaling", unresolvable, complex)] pub struct AutoProcScaling { /// An opaque unique identifier for the auto processing scaling pub auto_proc_scaling_id: u32, diff --git a/processed_data/src/graphql/mod.rs b/processed_data/src/graphql/mod.rs index f15adbf..1547ee6 100644 --- a/processed_data/src/graphql/mod.rs +++ b/processed_data/src/graphql/mod.rs @@ -6,12 +6,13 @@ use async_graphql::{ }; use aws_sdk_s3::presigning::PresigningConfig; use entities::{ - AutoProcIntegration, DataCollection, DataProcessing, ProcessingJob, ProcessingJobParameter, - AutoProc, AutoProcScaling, + AutoProc, AutoProcIntegration, AutoProcScaling, AutoProcScalingStatics, DataCollection, + DataProcessing, ProcessingJob, ProcessingJobParameter, }; use models::{ - auto_proc_integration, auto_proc_program, data_collection_file_attachment, processing_job, - processing_job_parameter, auto_proc, auto_proc_scaling, + auto_proc, auto_proc_integration, auto_proc_program, auto_proc_scaling, + auto_proc_scaling_statistics, data_collection_file_attachment, processing_job, + processing_job_parameter, }; use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter}; use std::time::Duration; @@ -62,6 +63,21 @@ impl DataCollection { .map(ProcessingJob::from) .collect()) } + + /// Fetches all the automatic process + async fn auto_proc_integration( + &self, + ctx: &Context<'_>, + ) -> async_graphql::Result, async_graphql::Error> { + let database = ctx.data::()?; + Ok(auto_proc_integration::Entity::find() + .filter(auto_proc_integration::Column::DataCollectionId.eq(self.id)) + .all(database) + .await? + .into_iter() + .map(AutoProcIntegration::from) + .collect()) + } } #[ComplexObject] @@ -85,6 +101,7 @@ impl DataProcessing { #[ComplexObject] impl ProcessingJob { + /// Fetches the processing job parameters async fn parameters( &self, ctx: &Context<'_>, @@ -102,6 +119,7 @@ impl ProcessingJob { #[ComplexObject] impl AutoProcIntegration { + /// Fetches the automatically processed programs async fn auto_proc_program( &self, ctx: &Context<'_>, @@ -119,14 +137,46 @@ impl AutoProcIntegration { #[ComplexObject] impl AutoProcProgram { - async fn auto_proc(&self, ctx: &Context<'_>,) -> async_graphql::Result> { + /// Fetched the automatic process + async fn auto_proc(&self, ctx: &Context<'_>) -> async_graphql::Result> { let database = ctx.data::()?; Ok(auto_proc::Entity::find() .filter(auto_proc::Column::AutoProcProgramId.eq(self.auto_proc_program_id)) .one(database) .await? - .map(AutoProc::from) + .map(AutoProc::from)) + } +} + +#[ComplexObject] +impl AutoProc { + /// Fetches the scaling for automatic process + async fn scaling(&self, ctx: &Context<'_>) -> async_graphql::Result> { + let database = ctx.data::()?; + Ok(auto_proc_scaling::Entity::find() + .filter(auto_proc_scaling::Column::AutoProcId.eq(self.auto_proc_id)) + .one(database) + .await? + .map(AutoProcScaling::from)) + } +} + +#[ComplexObject] +impl AutoProcScaling { + /// Fetches the scaling statistics + async fn statistics( + &self, + ctx: &Context<'_>, + ) -> async_graphql::Result> { + let database = ctx.data::()?; + Ok(auto_proc_scaling_statistics::Entity::find() + .filter( + auto_proc_scaling_statistics::Column::AutoProcScalingId + .eq(self.auto_proc_scaling_id), ) + .one(database) + .await? + .map(AutoProcScalingStatics::from)) } } @@ -137,19 +187,4 @@ impl Query { async fn router_data_collection(&self, id: u32) -> DataCollection { DataCollection { id } } - - async fn auto_proc_integration( - &self, - ctx: &Context<'_>, - data_collection_id: u32, - ) -> async_graphql::Result, async_graphql::Error> { - let database = ctx.data::()?; - Ok(auto_proc_integration::Entity::find() - .filter(auto_proc_integration::Column::DataCollectionId.eq(data_collection_id)) - .all(database) - .await? - .into_iter() - .map(AutoProcIntegration::from) - .collect()) - } }