Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make background validation performed by Services configurable #2060 #2150

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/fj-core/src/objects/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
Surface, Vertex,
},
storage::{Handle, HandleWrapper, ObjectId},
validate::{Validate, ValidationError},
validate::{Validate, ValidationConfig, ValidationError},
};

macro_rules! object {
Expand Down Expand Up @@ -40,6 +40,15 @@ macro_rules! object {
)*
}
}

/// Validate the object with a pre-defined validation configuration
pub fn validate_with_config(&self, config: &ValidationConfig, errors: &mut Vec<ValidationError>) {
match self {
$(
Self::$ty(object) => object.validate_with_config(config, errors),
)*
}
}
}

impl Object<WithHandle> {
Expand Down
13 changes: 12 additions & 1 deletion crates/fj-core/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod validation;

use crate::{
objects::{Object, Objects, WithHandle},
validate::ValidationErrors,
validate::{ValidationConfig, ValidationErrors},
};

pub use self::{
Expand Down Expand Up @@ -42,6 +42,17 @@ impl Services {
}
}

/// Construct an instance of `Services` with a pre-defined configuration for the validation service
pub fn with_validation_config(config: ValidationConfig) -> Self {
let objects = Service::<Objects>::default();
let validation =
Service::new(Validation::with_validation_config(config));
Self {
objects,
validation,
}
}

/// Insert an object into the stores
pub fn insert_object(&mut self, object: Object<WithHandle>) {
let mut object_events = Vec::new();
Expand Down
23 changes: 20 additions & 3 deletions crates/fj-core/src/services/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@ use std::{collections::BTreeMap, error::Error, thread};
use crate::{
objects::{BehindHandle, Object},
storage::ObjectId,
validate::ValidationError,
validate::{ValidationConfig, ValidationError},
};

use super::State;

/// Errors that occurred while validating the objects inserted into the stores
#[derive(Default)]
pub struct Validation {
/// All unhandled validation errors
pub errors: BTreeMap<ObjectId, ValidationError>,
/// Validation configuration for the validation service
config: ValidationConfig,
}

impl Validation {
/// A constructor for the validation service that allows a validation configuration to be set for the service
pub fn with_validation_config(config: ValidationConfig) -> Self {
let errors = BTreeMap::new();
Self { errors, config }
}
}

impl Default for Validation {
fn default() -> Self {
let errors = BTreeMap::new();
let config: ValidationConfig = ValidationConfig::default();
Self { errors, config }
}
}

impl Drop for Validation {
Expand Down Expand Up @@ -54,7 +71,7 @@ impl State for Validation {

match command {
ValidationCommand::ValidateObject { object } => {
object.validate(&mut errors);
object.validate_with_config(&self.config, &mut errors);

for err in errors {
events.push(ValidationEvent::ValidationFailed {
Expand Down