func (s *Service) LeaveTask(ctx context.Context, req *rpcscheduler.PeerTarget) error {
	peer, ok := s.resource.PeerManager().Load(req.PeerId)
	if !ok {
		logger.Errorf("leave task: peer %s is not exists", req.PeerId)
		return dferrors.Newf(base.Code_SchedPeerNotFound, "peer %s not found", req.PeerId)
	}

	peer.Log.Infof("leave task request: %#v", req)
	if err := peer.FSM.Event(resource.PeerEventLeave); err != nil {
		peer.Log.Errorf("peer fsm event failed: %v", err)
		return dferrors.Newf(base.Code_SchedTaskStatusError, err.Error())
	}

	peer.Children.Range(func(_, value interface{}) bool {
		child, ok := value.(*resource.Peer)
		if !ok {
			return true
		}

		// Reschedule a new parent to children of peer to exclude the current leave peer
		blocklist := set.NewSafeSet()
		blocklist.Add(peer.ID)

		s.scheduler.ScheduleParent(ctx, child, blocklist)
		return true
	})

	peer.DeleteParent()
	s.resource.PeerManager().Delete(peer.ID)
	return nil
}
// LeaveTask makes the peer unschedulable
LeaveTask makes the peer unschedulable
// LeaveTask makes the peer unschedulable
func (s *Service) LeaveTask(ctx context.Context, req *rpcscheduler.PeerTarget) error {
	peer, ok := s.resource.PeerManager().Load(req.PeerId)
	if !ok {
		logger.Errorf("leave task: peer %s is not exists", req.PeerId)
		return dferrors.Newf(base.Code_SchedPeerNotFound, "peer %s not found", req.PeerId)
	}
	peer.Log.Infof("leave task request: %#v", req)
	if err := peer.FSM.Event(resource.PeerEventLeave); err != nil {
		peer.Log.Errorf("peer fsm event failed: %v", err)
		return dferrors.Newf(base.Code_SchedTaskStatusError, err.Error())
	}
	peer.Children.Range(func(_, value interface{}) bool {
		child, ok := value.(*resource.Peer)
		if !ok {
			return true
		}
		blocklist := set.NewSafeSet()
		blocklist.Add(peer.ID)
		s.scheduler.ScheduleParent(ctx, child, blocklist)
		return true
	})
	peer.DeleteParent()
	s.resource.PeerManager().Delete(peer.ID)
	return nil
}
func ( s * Service ) LeaveTask ( ctx context . Context , req * rpcscheduler . PeerTarget ) error { peer , ok := s . resource . PeerManager ( ) . Load ( req . PeerId ) if ! ok { logger . Errorf ( " " , req . PeerId ) return dferrors . Newf ( base . Code_SchedPeerNotFound , " " , req . PeerId ) } peer . Log . Infof ( " " , req ) if err := peer . FSM . Event ( resource . PeerEventLeave ) ; err != nil { peer . Log . Errorf ( " " , err ) return dferrors . Newf ( base . Code_SchedTaskStatusError , err . Error ( ) ) } peer . Children . Range ( func ( _ , value interface { } ) bool { child , ok := value . ( * resource . Peer ) if ! ok { return true } blocklist := set . NewSafeSet ( ) blocklist . Add ( peer . ID ) s . scheduler . ScheduleParent ( ctx , child , blocklist ) return true } ) peer . DeleteParent ( ) s . resource . PeerManager ( ) . Delete ( peer . ID ) return nil }
LeaveTask makes the peer unschedulable
LeaveTask makes the peer unschedulable
// Reschedule a new parent to children of peer to exclude the current leave peer