package collector_go import ( sm "loafle.com/overflow/collector_go/scheduler" "log" ) type scheduleInfo struct { sensorId string interval string } type schedules []*scheduleInfo type Collector struct { scheduler sm.Scheduler } func (c *Collector) Start() { result := c.genSchedules() if len(result) <= 0 { return } c.scheduler = sm.Scheduler{} c.scheduler.Init() for i := 0; i < len(result); i++ { r := result[i] c.scheduler.NewSchedule(r.sensorId, r.interval, c.collect) } } func (c *Collector) Stop() { c.scheduler.RemoveAllSchedule() } func (c *Collector) AddSensor(container, crawler, id string) { s := c.genSchedule(container, crawler, id) c.scheduler.NewSchedule(s.sensorId, s.interval, c.collect) } func (c *Collector) RemoveSensor() { } func (c *Collector) collect(id string) { log.Println("collect ", id) } func (c *Collector) genSchedules() schedules { ss := make([]*scheduleInfo, 0) s1 := &scheduleInfo{ sensorId: "aa", interval: "3", } s2 := &scheduleInfo{ sensorId: "bb", interval: "5", } ss = append(ss, s1) ss = append(ss, s2) return ss } func (c *Collector) genSchedule(container, crawler, id string) *scheduleInfo { s := &scheduleInfo{ sensorId: "cc", interval: "5", } return s } // connection //func CallGet() { // // conn, err := grpc.Dial(address, grpc.WithInsecure()) // if err != nil { // log.Fatalf("did not connect: %v", err) // } // defer conn.Close() // // // dc := g.NewDataClient(conn); // // in := &g.Input{} // // in.Id = "" // in.Name = g.Crawlers_HEALTH_DNS // // // // out, err := dc.Get(context.Background(), in) //// // // if err != nil { // log.Println(err) // } // log.Println(out) // //}