(&self)
| 322 | |
| 323 | impl JobDef { |
| 324 | pub fn validate(&self) -> crate::Result<()> { |
| 325 | if self.tasks.is_empty() && self.array.is_none() { |
| 326 | return Err(HqError::DeserializationError("No tasks defined".into())); |
| 327 | } |
| 328 | |
| 329 | if let Some(array) = &self.array { |
| 330 | if !self.tasks.is_empty() { |
| 331 | return Err(HqError::DeserializationError( |
| 332 | "Definition of array job and individual task cannot be mixed".into(), |
| 333 | )); |
| 334 | } |
| 335 | if array.ids.is_none() && array.entries.is_empty() { |
| 336 | return Err(HqError::DeserializationError( |
| 337 | "One of attributes of array must be defined: 'ids', 'entries'".into(), |
| 338 | )); |
| 339 | } |
| 340 | if let Some(ids) = &array.ids |
| 341 | && !array.entries.is_empty() |
| 342 | && ids.id_count() as usize != array.entries.len() |
| 343 | { |
| 344 | return Err(HqError::DeserializationError( |
| 345 | "Items 'ids' and 'entries' does not match".into(), |
| 346 | )); |
| 347 | } |
| 348 | } |
| 349 | Ok(()) |
| 350 | } |
| 351 | |
| 352 | pub fn parse(str: &str) -> crate::Result<JobDef> { |
| 353 | let jdef: JobDef = toml::from_str(str)?; |
no test coverage detected