Skip to content

Commit 61a4f5c

Browse files
Autoproc scaling and statistics resolvers
1 parent 3b94f1d commit 61a4f5c

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

processed_data/src/graphql/entities.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl From<processing_job_parameter::Model> for ProcessingJobParameter {
7474

7575
/// Represents an auto processed job
7676
#[derive(Clone, Debug, PartialEq, SimpleObject)]
77-
#[graphql(name = "AutoProc", unresolvable)]
77+
#[graphql(name = "AutoProc", unresolvable, complex)]
7878
pub struct AutoProc {
7979
/// An opaque unique identifier for the auto processing
8080
pub auto_proc_id: u32,
@@ -170,7 +170,7 @@ impl From<auto_proc_integration::Model> for AutoProcIntegration {
170170

171171
/// Represents and auto processing scaling
172172
#[derive(Clone, Debug, PartialEq, SimpleObject)]
173-
#[graphql(name = "AutoProcScaling", unresolvable)]
173+
#[graphql(name = "AutoProcScaling", unresolvable, complex)]
174174
pub struct AutoProcScaling {
175175
/// An opaque unique identifier for the auto processing scaling
176176
pub auto_proc_scaling_id: u32,

processed_data/src/graphql/mod.rs

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ use async_graphql::{
66
};
77
use aws_sdk_s3::presigning::PresigningConfig;
88
use entities::{
9-
AutoProcIntegration, DataCollection, DataProcessing, ProcessingJob, ProcessingJobParameter,
10-
AutoProc, AutoProcScaling,
9+
AutoProc, AutoProcIntegration, AutoProcScaling, AutoProcScalingStatics, DataCollection,
10+
DataProcessing, ProcessingJob, ProcessingJobParameter,
1111
};
1212
use models::{
13-
auto_proc_integration, auto_proc_program, data_collection_file_attachment, processing_job,
14-
processing_job_parameter, auto_proc, auto_proc_scaling,
13+
auto_proc, auto_proc_integration, auto_proc_program, auto_proc_scaling,
14+
auto_proc_scaling_statistics, data_collection_file_attachment, processing_job,
15+
processing_job_parameter,
1516
};
1617
use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};
1718
use std::time::Duration;
@@ -62,6 +63,21 @@ impl DataCollection {
6263
.map(ProcessingJob::from)
6364
.collect())
6465
}
66+
67+
/// Fetches all the automatic process
68+
async fn auto_proc_integration(
69+
&self,
70+
ctx: &Context<'_>,
71+
) -> async_graphql::Result<Vec<AutoProcIntegration>, async_graphql::Error> {
72+
let database = ctx.data::<DatabaseConnection>()?;
73+
Ok(auto_proc_integration::Entity::find()
74+
.filter(auto_proc_integration::Column::DataCollectionId.eq(self.id))
75+
.all(database)
76+
.await?
77+
.into_iter()
78+
.map(AutoProcIntegration::from)
79+
.collect())
80+
}
6581
}
6682

6783
#[ComplexObject]
@@ -85,6 +101,7 @@ impl DataProcessing {
85101

86102
#[ComplexObject]
87103
impl ProcessingJob {
104+
/// Fetches the processing job parameters
88105
async fn parameters(
89106
&self,
90107
ctx: &Context<'_>,
@@ -102,6 +119,7 @@ impl ProcessingJob {
102119

103120
#[ComplexObject]
104121
impl AutoProcIntegration {
122+
/// Fetches the automatically processed programs
105123
async fn auto_proc_program(
106124
&self,
107125
ctx: &Context<'_>,
@@ -119,14 +137,46 @@ impl AutoProcIntegration {
119137

120138
#[ComplexObject]
121139
impl AutoProcProgram {
122-
async fn auto_proc(&self, ctx: &Context<'_>,) -> async_graphql::Result<Option<AutoProc>> {
140+
/// Fetched the automatic process
141+
async fn auto_proc(&self, ctx: &Context<'_>) -> async_graphql::Result<Option<AutoProc>> {
123142
let database = ctx.data::<DatabaseConnection>()?;
124143
Ok(auto_proc::Entity::find()
125144
.filter(auto_proc::Column::AutoProcProgramId.eq(self.auto_proc_program_id))
126145
.one(database)
127146
.await?
128-
.map(AutoProc::from)
147+
.map(AutoProc::from))
148+
}
149+
}
150+
151+
#[ComplexObject]
152+
impl AutoProc {
153+
/// Fetches the scaling for automatic process
154+
async fn scaling(&self, ctx: &Context<'_>) -> async_graphql::Result<Option<AutoProcScaling>> {
155+
let database = ctx.data::<DatabaseConnection>()?;
156+
Ok(auto_proc_scaling::Entity::find()
157+
.filter(auto_proc_scaling::Column::AutoProcId.eq(self.auto_proc_id))
158+
.one(database)
159+
.await?
160+
.map(AutoProcScaling::from))
161+
}
162+
}
163+
164+
#[ComplexObject]
165+
impl AutoProcScaling {
166+
/// Fetches the scaling statistics
167+
async fn statistics(
168+
&self,
169+
ctx: &Context<'_>,
170+
) -> async_graphql::Result<Option<AutoProcScalingStatics>> {
171+
let database = ctx.data::<DatabaseConnection>()?;
172+
Ok(auto_proc_scaling_statistics::Entity::find()
173+
.filter(
174+
auto_proc_scaling_statistics::Column::AutoProcScalingId
175+
.eq(self.auto_proc_scaling_id),
129176
)
177+
.one(database)
178+
.await?
179+
.map(AutoProcScalingStatics::from))
130180
}
131181
}
132182

@@ -137,19 +187,4 @@ impl Query {
137187
async fn router_data_collection(&self, id: u32) -> DataCollection {
138188
DataCollection { id }
139189
}
140-
141-
async fn auto_proc_integration(
142-
&self,
143-
ctx: &Context<'_>,
144-
data_collection_id: u32,
145-
) -> async_graphql::Result<Vec<AutoProcIntegration>, async_graphql::Error> {
146-
let database = ctx.data::<DatabaseConnection>()?;
147-
Ok(auto_proc_integration::Entity::find()
148-
.filter(auto_proc_integration::Column::DataCollectionId.eq(data_collection_id))
149-
.all(database)
150-
.await?
151-
.into_iter()
152-
.map(AutoProcIntegration::from)
153-
.collect())
154-
}
155190
}

0 commit comments

Comments
 (0)