fn single_iteration(self) -> impl Future<Item = (), Error = ()> {
        let State { hook,
                    service_group,
                    package,
                    svc_encrypted_password,
                    service_event_metadata,
                    supervisor,
                    nominal_interval,
                    service_health_result,
                    gateway_state, } = self;

        // Use an Arc to avoid having to have full clones everywhere. :/
        let service_group = Arc::new(service_group);
        let service_group_ref = Arc::clone(&service_group);

        if let Some(hook) = hook {
            let hr = hook_runner::HookRunner::new(hook,
                                                  service_group.deref().clone(),
                                                  package,
                                                  svc_encrypted_password);
            Either::A(hr.into_future()
                        .map(|(result, duration)| (result, Some(duration))))
        } else {
            let status = match supervisor.lock()
                                         .expect("couldn't unlock supervisor")
                                         .status()
            {
                (true, _) => HealthCheckResult::Ok,
                (false, _) => HealthCheckResult::Critical,
            };
            // no hook means no execution time!
            Either::B(lazy(move || Ok((status, None::<Duration>))))
        }.map_err(move |e| {
             error!("Error running health check hook for {}: {:?}",
                    service_group_ref, e)
         })
         .and_then(move |(check_result, duration)| {
             event::health_check(service_event_metadata, check_result, duration);
             debug!("Caching HealthCheckResult = '{}' for '{}'",
                    check_result, service_group);

             *service_health_result.lock()
                                   .expect("Could not unlock service_health_result") = check_result;
             gateway_state.write()
                          .expect("GatewayState lock is poisoned")
                          .health_check_data
                          .insert(service_group.deref().clone(), check_result);

             let interval = if check_result == HealthCheckResult::Ok {
                 // routine health check
                 nominal_interval
             } else {
                 // special health check interval
                 HealthCheckInterval::default()
             };

             trace!("Next health check for {} in {}", service_group, interval);

             let instant =
                 Instant::now().checked_add(interval.into())
                               .expect("This should never happen with normal health check \
                                        interval sizes");
             tokio_timer::timer::Handle::current().delay(instant)
                                                  .map_err(move |timer_error| {
                                                      if timer_error.is_shutdown() {
                                                          warn!("Timer for {} health check shut \
                                                                 down!",
                                                                service_group);
                                                      }
                                                      if timer_error.is_at_capacity() {
                                                          warn!("Timer for {} health check is at \
                                                                 capacity!",
                                                                service_group);
                                                      }
                                                  })
         })
    }
/// Creates a future that runs the health check and then waits for
/// a suitable interval. Multiple such iterations will then be
/// chained together for an unending stream of health checks.
Creates a future that runs the health check and then waits for
a suitable interval. Multiple such iterations will then be
chained together for an unending stream of health checks.
Creates a future that runs the health check and then waits for a suitable interval . Multiple such iterations will then be chained together for an unending stream of health checks .
fn single_iteration(self) -> impl Future<Item = (), Error = ()> {
        let State { hook,
                    service_group,
                    package,
                    svc_encrypted_password,
                    service_event_metadata,
                    supervisor,
                    nominal_interval,
                    service_health_result,
                    gateway_state, } = self;
        // Use an Arc to avoid having to have full clones everywhere. :/
        let service_group = Arc::new(service_group);
        let service_group_ref = Arc::clone(&service_group);
        if let Some(hook) = hook {
            let hr = hook_runner::HookRunner::new(hook,
                                                  service_group.deref().clone(),
                                                  package,
                                                  svc_encrypted_password);
            Either::A(hr.into_future()
                        .map(|(result, duration)| (result, Some(duration))))
        } else {
            let status = match supervisor.lock()
                                         .expect("couldn't unlock supervisor")
                                         .status()
            {
                (true, _) => HealthCheckResult::Ok,
                (false, _) => HealthCheckResult::Critical,
            };
            // no hook means no execution time!
            Either::B(lazy(move || Ok((status, None::<Duration>))))
        }.map_err(move |e| {
             error!("Error running health check hook for {}: {:?}",
                    service_group_ref, e)
         })
         .and_then(move |(check_result, duration)| {
             event::health_check(service_event_metadata, check_result, duration);
             debug!("Caching HealthCheckResult = '{}' for '{}'",
                    check_result, service_group);
             *service_health_result.lock()
                                   .expect("Could not unlock service_health_result") = check_result;
             gateway_state.write()
                          .expect("GatewayState lock is poisoned")
                          .health_check_data
                          .insert(service_group.deref().clone(), check_result);
             let interval = if check_result == HealthCheckResult::Ok {
                 // routine health check
                 nominal_interval
             } else {
                 // special health check interval
                 HealthCheckInterval::default()
             };
             trace!("Next health check for {} in {}", service_group, interval);
             let instant =
                 Instant::now().checked_add(interval.into())
                               .expect("This should never happen with normal health check \
                                        interval sizes");
             tokio_timer::timer::Handle::current().delay(instant)
                                                  .map_err(move |timer_error| {
                                                      if timer_error.is_shutdown() {
                                                          warn!("Timer for {} health check shut \
                                                                 down!",
                                                                service_group);
                                                      }
                                                      if timer_error.is_at_capacity() {
                                                          warn!("Timer for {} health check is at \
                                                                 capacity!",
                                                                service_group);
                                                      }
                                                  })
         })
    }
fn single_iteration ( self ) -> impl Future < Item = ( ) , Error = ( ) > { let State { hook , service_group , package , svc_encrypted_password , service_event_metadata , supervisor , nominal_interval , service_health_result , gateway_state , } = self ; // Use an Arc to avoid having to have full clones everywhere. :/ let service_group = Arc :: new ( service_group ) ; let service_group_ref = Arc :: clone ( & service_group ) ; if let Some ( hook ) = hook { let hr = hook_runner :: HookRunner :: new ( hook , service_group . deref ( ) . clone ( ) , package , svc_encrypted_password ) ; Either :: A ( hr . into_future ( ) . map ( | ( result , duration ) | ( result , Some ( duration ) ) ) ) } else { let status = match supervisor . lock ( ) . expect ( " " ) . status ( ) { ( true , _ ) => HealthCheckResult :: Ok , ( false , _ ) => HealthCheckResult :: Critical , } ; // no hook means no execution time! Either :: B ( lazy ( move | | Ok ( ( status , None :: < Duration > ) ) ) ) } . map_err ( move | e | { error ! ( " " service_group_ref e ) } ) . and_then ( move | ( check_result , duration ) | { event :: health_check ( service_event_metadata , check_result , duration ) ; debug ! ( " " check_result service_group ) ; * service_health_result . lock ( ) . expect ( " " ) = check_result ; gateway_state . write ( ) . expect ( " " ) . health_check_data . insert ( service_group . deref ( ) . clone ( ) , check_result ) ; let interval = if check_result == HealthCheckResult :: Ok { // routine health check nominal_interval } else { // special health check interval HealthCheckInterval :: default ( ) } ; trace ! ( " " service_group interval ) ; let instant = Instant :: now ( ) . checked_add ( interval . into ( ) ) . expect ( " \
 " ) ; tokio_timer :: timer :: Handle :: current ( ) . delay ( instant ) . map_err ( move | timer_error | { if timer_error . is_shutdown ( ) { warn ! ( " \
 " service_group ) ; } if timer_error . is_at_capacity ( ) { warn ! ( " \
 " service_group ) ; } } ) } ) }
Creates a future that runs the health check and then waits for
a suitable interval.
Creates a future that runs the health check and then waits for a suitable interval .
self
self