pub(crate) fn launch_optimization(
        optimizers: Arc<Vec<Arc<Optimizer>>>,
        segments: LockedSegmentHolder,
    ) -> Vec<StoppableTaskHandle<bool>> {
        let mut scheduled_segment_ids: HashSet<_> = Default::default();
        let mut handles = vec![];
        for optimizer in optimizers.iter() {
            loop {
                let nonoptimal_segment_ids =
                    optimizer.check_condition(segments.clone(), &scheduled_segment_ids);
                if nonoptimal_segment_ids.is_empty() {
                    break;
                } else {
                    let optim = optimizer.clone();
                    let segs = segments.clone();
                    let nsi = nonoptimal_segment_ids.clone();
                    for sid in &nsi {
                        scheduled_segment_ids.insert(*sid);
                    }

                    handles.push(spawn_stoppable(move |stopped| {
                        match optim.as_ref().optimize(segs, nsi, stopped) {
                            Ok(result) => result,
                            Err(error) => match error {
                                CollectionError::Cancelled { description } => {
                                    log::info!("Optimization cancelled - {}", description);
                                    false
                                }
                                _ => {
                                    // Error of the optimization can not be handled by API user
                                    // It is only possible to fix after full restart,
                                    // so the best available action here is to stop whole
                                    // optimization thread and log the error
                                    panic!("Optimization error: {}", error);
                                }
                            },
                        }
                    }));
                }
            }
        }
        handles
    }
/// Checks conditions for all optimizers until there is no suggested segment
/// Starts a task for each optimization
/// Returns handles for started tasks
Checks conditions for all optimizers until there is no suggested segment
Starts a task for each optimization
Returns handles for started tasks
Checks conditions for all optimizers until there is no suggested segment Starts a task for each optimization Returns handles for started tasks
pub(crate) fn launch_optimization(
        optimizers: Arc<Vec<Arc<Optimizer>>>,
        segments: LockedSegmentHolder,
    ) -> Vec<StoppableTaskHandle<bool>> {
        let mut scheduled_segment_ids: HashSet<_> = Default::default();
        let mut handles = vec![];
        for optimizer in optimizers.iter() {
            loop {
                let nonoptimal_segment_ids =
                    optimizer.check_condition(segments.clone(), &scheduled_segment_ids);
                if nonoptimal_segment_ids.is_empty() {
                    break;
                } else {
                    let optim = optimizer.clone();
                    let segs = segments.clone();
                    let nsi = nonoptimal_segment_ids.clone();
                    for sid in &nsi {
                        scheduled_segment_ids.insert(*sid);
                    }
                    handles.push(spawn_stoppable(move |stopped| {
                        match optim.as_ref().optimize(segs, nsi, stopped) {
                            Ok(result) => result,
                            Err(error) => match error {
                                CollectionError::Cancelled { description } => {
                                    log::info!("Optimization cancelled - {}", description);
                                    false
                                }
                                _ => {
                                    // Error of the optimization can not be handled by API user
                                    // It is only possible to fix after full restart,
                                    // so the best available action here is to stop whole
                                    // optimization thread and log the error
                                    panic!("Optimization error: {}", error);
                                }
                            },
                        }
                    }));
                }
            }
        }
        handles
    }
pub ( crate ) fn launch_optimization ( optimizers : Arc < Vec < Arc < Optimizer > > > , segments : LockedSegmentHolder , ) -> Vec < StoppableTaskHandle < bool > > { let mut scheduled_segment_ids : HashSet < _ > = Default :: default ( ) ; let mut handles = vec ! [ ] ; for optimizer in optimizers . iter ( ) { loop { let nonoptimal_segment_ids = optimizer . check_condition ( segments . clone ( ) , & scheduled_segment_ids ) ; if nonoptimal_segment_ids . is_empty ( ) { break ; } else { let optim = optimizer . clone ( ) ; let segs = segments . clone ( ) ; let nsi = nonoptimal_segment_ids . clone ( ) ; for sid in & nsi { scheduled_segment_ids . insert ( * sid ) ; } handles . push ( spawn_stoppable ( move | stopped | { match optim . as_ref ( ) . optimize ( segs , nsi , stopped ) { Ok ( result ) => result , Err ( error ) => match error { CollectionError :: Cancelled { description } => { log :: info ! ( " " description ) ; false } _ => { // Error of the optimization can not be handled by API user // It is only possible to fix after full restart, // so the best available action here is to stop whole // optimization thread and log the error panic ! ( " " error ) ; } } , } } ) ) ; } } } handles }
Checks conditions for all optimizers until there is no suggested segment
Starts a task for each optimization
Returns handles for started tasks
Checks conditions for all optimizers until there is no suggested segment Starts a task for each optimization Returns handles for started tasks
optimizers
Arc<Vec<Arc<Optimizer>>>
segments
LockedSegmentHolder
optimizers
Arc<Vec<Arc<Optimizer>>>
segments
LockedSegmentHolder