-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_poll.go
56 lines (45 loc) · 871 Bytes
/
tx_poll.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package tail
import (
"os"
"time"
)
func (tx *Tx) poll(td time.Duration, timeout time.Duration) {
if tx.stat == nil {
return
}
if tx.after > 0 {
time.Sleep(tx.after)
}
tk := time.NewTicker(td)
defer tk.Stop()
tm := time.NewTicker(timeout)
defer tm.Stop()
for {
select {
case <-tm.C:
xEnv.Errorf("%s tx poll timeout", tx.fx.path)
return
case <-tk.C:
st, er := os.Stat(tx.fx.path)
if er != nil {
if os.IsNotExist(er) {
xEnv.Errorf("%s file not found", tx.fx.path)
return
}
xEnv.Errorf("%s file open stat error %v", tx.fx.path, er)
continue
}
//是否修改
if tx.stat.ModTime().Unix() == st.ModTime().Unix() {
continue
}
if st.Size() != tx.stat.Size() {
tx.reopen()
return
}
case <-tx.fx.tom.Dying():
xEnv.Errorf("%s poll exit succeed", tx.fx.path)
return
}
}
}