revid: simplified multiSender Write method

This commit is contained in:
Saxon 2019-03-12 15:13:24 +10:30
parent 1c75867ba5
commit 30ea5d74f6
1 changed files with 13 additions and 17 deletions

View File

@ -57,6 +57,7 @@ type Sender interface {
type multiSender struct { type multiSender struct {
owner *Revid owner *Revid
senders []loadSender senders []loadSender
retry bool
} }
// newMultiSender returns a pointer to a new multiSender. // newMultiSender returns a pointer to a new multiSender.
@ -69,28 +70,23 @@ func newMultiSender(owner *Revid, senders []loadSender) *multiSender {
// sends we notify the current sender to take any required actions and then try // sends we notify the current sender to take any required actions and then try
// the send again. // the send again.
func (s *multiSender) Write(d []byte) (int, error) { func (s *multiSender) Write(d []byte) (int, error) {
for i, sender := range s.senders { for _, sender := range s.senders {
sender.load(d) sender.load(d)
for s.owner.IsRunning() {
err := sender.send() err := sender.send()
if err != nil { if err != nil {
s.owner.config.Logger.Log(logger.Warning, "send failed", "output", i, "error", err)
s.handleFail(sender, err) s.handleFail(sender, err)
if s.owner.config.SendRetry {
for {
if !s.owner.IsRunning() {
sender.release()
return 0, err
} }
err = sender.send() if err == nil || !s.retry {
if err == nil {
break break
} }
s.handleFail(sender, err)
}
} }
} }
for _, sender := range s.senders {
sender.release() sender.release()
} }
return len(d), nil return len(d), nil
} }