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

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

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

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

33 34 35 36 37 38 39 40 41 42 43 44
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
45 46 47
		}
	}
}
48

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
func (this *WasuChecker) checkSite() {
	for _, tmp := range this.Config.Sites.Items() {
		site := tmp.(map[string]interface{})
		siteid:= site["id"].(string);
		if !this.queue.Has(siteid) {
			this.queue.Set(siteid, "running")
			//spModel := new(Wasu.SpModel)
			//spModel.Config = this.Config
			//spModel.Spid = spid
			siteModel := new(Pull.SiteModel)
			siteModel.Config=this.Config
			siteModel.Siteid=siteid
			go siteModel.Start()
		}
	}
}