/// Perform update check and handle the result, including updating the update check context
/// and cohort.
Perform update check and handle the result, including updating the update check context
and cohort.
Perform update check and handle the result including updating the update check context and cohort .
pub async fn start_update_check(
        &mut self,
        options: CheckOptions,
        co: &mut async_generator::Yield<StateMachineEvent>,
    ) {
        let apps = self.app_set.to_vec().await;
        let result = self.perform_update_check(options, self.context.clone(), apps, co).await;
        match &result {
            Ok(result) => {
                info!("Update check result: {:?}", result);
                // Update check succeeded, update |last_update_time|.
                self.context.schedule.last_update_time = clock::now();
                // Update the service dictated poll interval (which is an Option<>, so doesn't
                // need to be tested for existence here).
                self.context.state.server_dictated_poll_interval =
                    result.server_dictated_poll_interval;
                // Increment |consecutive_failed_update_attempts| if any app failed to install,
                // otherwise reset it to 0.
                if result
                    .app_responses
                    .iter()
                    .any(|app| app.result == update_check::Action::InstallPlanExecutionError)
                {
                    self.context.state.consecutive_failed_update_attempts += 1;
                } else {
                    self.context.state.consecutive_failed_update_attempts = 0;
                }
                // Update check succeeded, reset |consecutive_failed_update_checks| to 0.
                self.context.state.consecutive_failed_update_checks = 0;
                self.app_set.update_from_omaha(&result.app_responses).await;
                self.report_attempts_to_succeed(true).await;
                // TODO: update consecutive_proxied_requests
            }
            Err(error) => {
                error!("Update check failed: {:?}", error);
                // Update check failed, increment |consecutive_failed_update_checks|.
                self.context.state.consecutive_failed_update_checks += 1;
                let failure_reason = match error {
                    UpdateCheckError::ResponseParser(_) | UpdateCheckError::InstallPlan(_) => {
                        // We talked to Omaha, update |last_update_time|.
                        self.context.schedule.last_update_time = clock::now();
                        UpdateCheckFailureReason::Omaha
                    }
                    UpdateCheckError::Policy(_) => UpdateCheckFailureReason::Internal,
                    UpdateCheckError::OmahaRequest(request_error) => match request_error {
                        OmahaRequestError::Json(_) | OmahaRequestError::HttpBuilder(_) => {
                            UpdateCheckFailureReason::Internal
                        }
                        OmahaRequestError::Hyper(_) | OmahaRequestError::HttpStatus(_) => {
                            UpdateCheckFailureReason::Network
                        }
                    },
                };
                self.report_metrics(Metrics::UpdateCheckFailureReason(failure_reason));
                self.report_attempts_to_succeed(false).await;
            }
        }
        co.yield_(StateMachineEvent::ScheduleChange(self.context.schedule.clone())).await;
        co.yield_(StateMachineEvent::ProtocolStateChange(self.context.state.clone())).await;
        co.yield_(StateMachineEvent::UpdateCheckResult(result)).await;
        self.persist_data().await;
        // TODO: This is the last place we read self.state, we should see if we can find another
        // way to achieve this so that we can remove self.state entirely.
        if self.state == State::WaitingForReboot {
            info!("Rebooting the system at the end of a successful update");
            if let Err(e) = self.installer.perform_reboot().await {
                error!("Unable to reboot the system: {}", e);
            }
        }
        self.set_state(State::Idle, co).await;
    }
pub async fn start_update_check ( & mut self , options : CheckOptions , co : & mut async_generator :: Yield < StateMachineEvent > , ) { let apps = self . app_set . to_vec ( ) . await ; let result = self . perform_update_check ( options , self . context . clone ( ) , apps , co ) . await ; match & result { Ok ( result ) => { info ! ( " " result ) ; // Update check succeeded, update |last_update_time|. self . context . schedule . last_update_time = clock :: now ( ) ; // Update the service dictated poll interval (which is an Option<>, so doesn't // need to be tested for existence here). self . context . state . server_dictated_poll_interval = result . server_dictated_poll_interval ; // Increment |consecutive_failed_update_attempts| if any app failed to install, // otherwise reset it to 0. if result . app_responses . iter ( ) . any ( | app | app . result == update_check :: Action :: InstallPlanExecutionError ) { self . context . state . consecutive_failed_update_attempts += 1 ; } else { self . context . state . consecutive_failed_update_attempts = 0 ; } // Update check succeeded, reset |consecutive_failed_update_checks| to 0. self . context . state . consecutive_failed_update_checks = 0 ; self . app_set . update_from_omaha ( & result . app_responses ) . await ; self . report_attempts_to_succeed ( true ) . await ; // TODO: update consecutive_proxied_requests } Err ( error ) => { error ! ( " " error ) ; // Update check failed, increment |consecutive_failed_update_checks|. self . context . state . consecutive_failed_update_checks += 1 ; let failure_reason = match error { UpdateCheckError :: ResponseParser ( _ ) | UpdateCheckError :: InstallPlan ( _ ) => { // We talked to Omaha, update |last_update_time|. self . context . schedule . last_update_time = clock :: now ( ) ; UpdateCheckFailureReason :: Omaha } UpdateCheckError :: Policy ( _ ) => UpdateCheckFailureReason :: Internal , UpdateCheckError :: OmahaRequest ( request_error ) => match request_error { OmahaRequestError :: Json ( _ ) | OmahaRequestError :: HttpBuilder ( _ ) => { UpdateCheckFailureReason :: Internal } OmahaRequestError :: Hyper ( _ ) | OmahaRequestError :: HttpStatus ( _ ) => { UpdateCheckFailureReason :: Network } } , } ; self . report_metrics ( Metrics :: UpdateCheckFailureReason ( failure_reason ) ) ; self . report_attempts_to_succeed ( false ) . await ; } } co . yield_ ( StateMachineEvent :: ScheduleChange ( self . context . schedule . clone ( ) ) ) . await ; co . yield_ ( StateMachineEvent :: ProtocolStateChange ( self . context . state . clone ( ) ) ) . await ; co . yield_ ( StateMachineEvent :: UpdateCheckResult ( result ) ) . await ; self . persist_data ( ) . await ; // TODO: This is the last place we read self.state, we should see if we can find another // way to achieve this so that we can remove self.state entirely. if self . state == State :: WaitingForReboot { info ! ( " " ) ; if let Err ( e ) = self . installer . perform_reboot ( ) . await { error ! ( " " e ) ; } } self . set_state ( State :: Idle , co ) . await ; }
Perform update check and handle the result, including updating the update check context
and cohort.
Perform update check and handle the result including updating the update check context and cohort .
&mut self
options
CheckOptions
co
&mut async_generator::Yield<StateMachineEvent>