From ce344d6f50030676339d84909b21a5ee065cdfed Mon Sep 17 00:00:00 2001 From: "insanity@loafle.com" Date: Tue, 23 May 2017 11:13:11 +0900 Subject: [PATCH] poller --- poller.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/poller.go b/poller.go index a33a2cd..b55ac11 100644 --- a/poller.go +++ b/poller.go @@ -7,6 +7,8 @@ import ( "log" "strconv" "sync" + "time" + "loafle.com/overflow/agent_api/messages" ) const ( @@ -87,10 +89,29 @@ func (p *Poller) stop() { p.scheduler.Stop() } +var once1 sync.Once func (p *Poller) polling(agentId string) { go func() { log.Println("POLLING....") + + time.Sleep(time.Second * 20) + + + once1.Do(func() { + + newTask := messages.AgentTask{} + newTask.Command = messages.TASK_POL_INTERVAL_UPDATE + param := make(map[string]string) + param["interval"] = "3" + newTask.Params = param + + p.taskCh <- newTask + }) + + + + /* addr := p.gconf.Central.Address + ":" + string(p.gconf.Central.Port) conn, err := grpc.Dial(addr, grpc.WithInsecure()) @@ -115,6 +136,7 @@ func (p *Poller) polling(agentId string) { func (p *Poller) updateInterval(interval int) { p.scheduler.UpdateInterval(POLLING_ID, uint64(interval)) + log.Printf("Polling interval has changed to %d seconds.\n", interval) } /*