Example #1
0
func (r *RedisSentinel) Do(action string, params ...interface{}) (result interface{}, err error) {
	var conn Connection
	err = waitfor.Func(func() (err error) {
		conn, err = r.getConn()
		return
	}, time.Duration(1)*time.Millisecond, r.callTimeout)
	if err != nil {
		return
	}

	defer conn.Close()
	err = waitfor.Func(func() (err error) {
		result, err = conn.Do(action, params...)
		return
	}, time.Duration(1)*time.Millisecond, r.callTimeout)
	if err != nil {
		if strings.Contains(err.Error(), "You can't write against a read only slave.") { // this is very hacky
			err = r.RebuildConnectionPool()
			if err != nil {
				return
			}
			result, err = r.Do(action, params...)
		} else {
			return
		}
	}
	return
}
Example #2
0
// retry makes a request to apid with retries on fail
func (a *Adaptor) retry(apidFunction string, params url.Values, result interface{}) *adaptor.AdaptorError {
	wrapper := func() error {
		return a.apidClient.DoFunction("checkFeatureToggle", params, result)
	}

	err := waitfor.Func(wrapper, a.interval, a.timeout)
	if err != nil {
		formattedErr := adaptor.NewError(err.Error())
		return formattedErr
	}

	return nil
}