Beispiel #1
0
func (manager *DrainManager) StartDrain(name, uri string, retry retry.Retryer) {
	manager.mux.Lock()
	defer manager.mux.Unlock()

	var stateChangeFn state.StateChangedFn

	_, exists := manager.stmMap[name]
	if exists {
		// Stop the running drain first.
		manager.stopDrain(name, false)
	} else {
		stateChangeFn = func(state state.State, rev int64) {
			manager.stateCache.SetState(name, state, rev)
		}
	}

	process, err := NewDrainProcess(name, uri)
	if err != nil {
		log.Error(process.Logf("Couldn't create drain: %v", err))
		return
	}
	drainStm := state.NewStateMachine("Drain", process, retry, stateChangeFn)
	manager.stmMap[name] = drainStm

	if err = drainStm.SendAction(state.START); err != nil {
		log.Fatalf("Failed to start drain %s; %v", name, err)
	}
}
Beispiel #2
0
// NewRetryerForDrain chooses
func NewRetryerForDrain(name string) retry.Retryer {
	var retryLimit time.Duration
	var err error
	for prefix, duration := range logyard.GetConfig().RetryLimits {
		if strings.HasPrefix(name, prefix) {
			if retryLimit, err = time.ParseDuration(duration); err != nil {
				log.Error("[drain:%s] Invalid duration (%s) for drain prefix %s "+
					"-- %s -- using default value (infinite)",
					name, duration, prefix, err)
				retryLimit = time.Duration(0)
			}
			if retryLimit <= retry.RESET_AFTER {
				log.Error("[drain:%s] Invalid retry limit (%v) -- must be >%v -- "+
					"using default value (infinite)",
					name, retryLimit, retry.RESET_AFTER)
				retryLimit = time.Duration(0)
			}
			break
		}
	}
	log.Infof("[drain:%s] Choosing retry limit %v", name, retryLimit)
	return retry.NewProgressiveRetryer(retryLimit)
}