()
| 69 | } |
| 70 | |
| 71 | func (this *IPListManager) Start() { |
| 72 | this.Init() |
| 73 | |
| 74 | // 第一次读取 |
| 75 | err := this.Loop() |
| 76 | if err != nil { |
| 77 | remotelogs.ErrorObject("IP_LIST_MANAGER", err) |
| 78 | } |
| 79 | |
| 80 | this.ticker = time.NewTicker(60 * time.Second) |
| 81 | if Tea.IsTesting() { |
| 82 | this.ticker = time.NewTicker(10 * time.Second) |
| 83 | } |
| 84 | var countErrors = 0 |
| 85 | for { |
| 86 | select { |
| 87 | case <-this.ticker.C: |
| 88 | case <-IPListUpdateNotify: |
| 89 | } |
| 90 | err = this.Loop() |
| 91 | if err != nil { |
| 92 | countErrors++ |
| 93 | |
| 94 | remotelogs.ErrorObject("IP_LIST_MANAGER", err) |
| 95 | |
| 96 | // 连续错误小于3次的我们立即重试 |
| 97 | if countErrors <= 3 { |
| 98 | select { |
| 99 | case IPListUpdateNotify <- true: |
| 100 | default: |
| 101 | } |
| 102 | } |
| 103 | } else { |
| 104 | countErrors = 0 |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | func (this *IPListManager) Stop() { |
| 110 | if this.ticker != nil { |
nothing calls this directly
no test coverage detected