refactor this part of code for upcoming change
This commit is contained in:
parent
929590016a
commit
941cc3e301
45
tail.go
45
tail.go
|
@ -213,31 +213,27 @@ func (tail *Tail) tailFileSync() {
|
||||||
for {
|
for {
|
||||||
line, err := tail.readLine()
|
line, err := tail.readLine()
|
||||||
|
|
||||||
switch err {
|
if err == nil {
|
||||||
case nil:
|
cooloff := !tail.sendLine(line)
|
||||||
if true {
|
if cooloff {
|
||||||
cooloff := !tail.sendLine(line)
|
// Wait a second before seeking till the end of
|
||||||
if cooloff {
|
// file when rate limit is reached.
|
||||||
// Wait a second before seeking till the end of
|
msg := fmt.Sprintf(
|
||||||
// file when rate limit is reached.
|
"Too much log activity; waiting a second " +
|
||||||
msg := fmt.Sprintf(
|
"before resuming tailing")
|
||||||
"Too much log activity; waiting a second " +
|
tail.Lines <- &Line{msg, time.Now(), fmt.Errorf(msg)}
|
||||||
"before resuming tailing")
|
select {
|
||||||
tail.Lines <- &Line{msg, time.Now(), fmt.Errorf(msg)}
|
case <-time.After(time.Second):
|
||||||
select {
|
case <-tail.Dying():
|
||||||
case <-time.After(time.Second):
|
return
|
||||||
case <-tail.Dying():
|
}
|
||||||
return
|
err = tail.seekEnd()
|
||||||
}
|
if err != nil {
|
||||||
err = tail.seekEnd()
|
tail.Kill(err)
|
||||||
if err != nil {
|
return
|
||||||
tail.Kill(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case io.EOF:
|
}else if err == io.EOF {
|
||||||
// XXX: should `line` be returned at this point?
|
|
||||||
if !tail.Follow {
|
if !tail.Follow {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -251,7 +247,8 @@ func (tail *Tail) tailFileSync() {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default: // non-EOF error
|
}else {
|
||||||
|
// non-EOF error
|
||||||
tail.Killf("Error reading %s: %s", tail.Filename, err)
|
tail.Killf("Error reading %s: %s", tail.Filename, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue