Skip to content

Commit

Permalink
Merge pull request #2150 from brungardtdb/brungardtdb/configure_backg…
Browse files Browse the repository at this point in the history
…round_validation

 Make background validation performed by Services configurable #2060
  • Loading branch information
hannobraun authored Jan 14, 2024
2 parents 5015bb2 + f57c77e commit 9d992aa
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
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

0 comments on commit 9d992aa

Please sign in to comment.