| 50 | } |
| 51 | |
| 52 | func (this *Manager) Start() { |
| 53 | remotelogs.Println("AGENT_MANAGER", "starting ...") |
| 54 | |
| 55 | err := this.loadDB() |
| 56 | if err != nil { |
| 57 | remotelogs.Error("AGENT_MANAGER", "load database failed: "+err.Error()) |
| 58 | return |
| 59 | } |
| 60 | |
| 61 | // 从本地数据库中加载 |
| 62 | err = this.Load() |
| 63 | if err != nil { |
| 64 | remotelogs.Error("AGENT_MANAGER", "load failed: "+err.Error()) |
| 65 | } |
| 66 | |
| 67 | // 先从API获取 |
| 68 | err = this.LoopAll() |
| 69 | if err != nil { |
| 70 | if rpc.IsConnError(err) { |
| 71 | remotelogs.Debug("AGENT_MANAGER", "retrieve latest agent ip failed: "+err.Error()) |
| 72 | } else { |
| 73 | remotelogs.Error("AGENT_MANAGER", "retrieve latest agent ip failed: "+err.Error()) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // 定时获取 |
| 78 | var duration = 30 * time.Minute |
| 79 | if Tea.IsTesting() { |
| 80 | duration = 30 * time.Second |
| 81 | } |
| 82 | var ticker = time.NewTicker(duration) |
| 83 | for range ticker.C { |
| 84 | err = this.LoopAll() |
| 85 | if err != nil { |
| 86 | remotelogs.Error("AGENT_MANAGER", "retrieve latest agent ip failed: "+err.Error()) |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func (this *Manager) Load() error { |
| 92 | var offset int64 = 0 |