WasuChecker.go 1001 Bytes
Newer Older
吴贤德's avatar
吴贤德 committed
1 2 3
package Controller

import (
4
	cmap "github.com/orcaman/concurrent-map"
吴贤德's avatar
吴贤德 committed
5 6 7 8 9 10 11 12
	"src/Common/Unit"
	"src/Config"
	"src/Model/Wasu"
	"time"
)

type WasuChecker struct {
	Config *Config.Config
13
	queue cmap.ConcurrentMap
吴贤德's avatar
吴贤德 committed
14 15 16
}

func (this *WasuChecker) Start() {
17 18
	this.queue =cmap.New()
	//定时遍历SP,检查SP是否启动
吴贤德's avatar
吴贤德 committed
19 20
	go func() {
	START:
21
		s, ok := this.Config.Sys.Get("config_sp_check_seconds")
吴贤德's avatar
吴贤德 committed
22
		if ok {
23 24
			this.check()
			n := Unit.Time2Seconds(s.(string))+10
吴贤德's avatar
吴贤德 committed
25 26 27 28 29 30
			time.Sleep(time.Duration(n) * time.Second)
		}
		goto START
	}()
}

31 32 33 34 35 36 37 38 39 40 41 42
func (this *WasuChecker) check() {
	for _, tmp := range this.Config.Sps.Items() {
		sp := tmp.(map[string]interface{})
		spid:= sp["id"].(string);
		if !this.queue.Has(spid) {
			this.queue.Set(spid, "running")
			spModel := new(Wasu.SpModel)
			spModel.Config = this.Config
			spModel.Spid = spid
			//st, _ := DateTime.Parse("YYYY-MM-DD hh:mm:ss", sp["push_offset"].(string))
			//spModel.StartTime = DateTime.Format("YYYYMMDDhhmmss", st)
			go spModel.Start()
吴贤德's avatar
吴贤德 committed
43 44 45
		}
	}
}
46