Exemplo n.º 1
0
func send(m *Member, msg *protos.Message) error {
	if !m.active {
		return fmt.Errorf("Ommitting member %s due to inactive status.", m.address)
	}

	conn, err := grpc.Dial(m.address, grpc.WithTimeout(1000*time.Millisecond))
	if err != nil {
		m.active = false
		return err
	}
	defer conn.Close()

	client := protos.NewDMapClient(conn)
	resp, err := client.Send(context.Background(), msg)
	if resp.Code != OK {
		return fmt.Errorf("Can't update all peers! Status code: %d", resp.Code)
	}

	return nil
}
Exemplo n.º 2
0
func checkHealth(origin string, m *Member) error {
	conn, err := grpc.Dial(m.address, grpc.WithTimeout(100*time.Millisecond))
	if err != nil {
		m.active = false
		return fmt.Errorf("Member %s is unavailable! Err: %v", m.address, err)
	}
	defer conn.Close()

	client := protos.NewDMapClient(conn)
	message := &protos.HealthCheck{
		Origin: origin,
	}

	if resp, err := client.Ping(context.Background(), message); resp.Code != OK || err != nil {
		m.active = false
		return fmt.Errorf("Member %s is unavailable! Code: %d. Err: %v", m.address, resp.Code, err)
	} else {
		m.active = true
		log.Infof("Member %s active", m.address)
	}

	return nil
}