add waitor

This commit is contained in:
eson 2018-12-17 03:22:25 +08:00
parent 4d50b03400
commit da98287e2e
2 changed files with 15 additions and 3 deletions

8
dip.go
View File

@ -45,6 +45,7 @@ func (worker *DIPWorker) ShowGroupInfo() string {
type DIPGroup struct {
Group map[string]*DHost // 原始参照
Waitor map[string]*DHost
Ready map[string]*DHost
IPTableNum string
Current *DHost
@ -55,11 +56,13 @@ type DIPGroup struct {
func NewDIPGroup() *DIPGroup {
group := DIPGroup{}
group.Group = make(map[string]*DHost)
group.Waitor = make(map[string]*DHost)
group.Ready = make(map[string]*DHost)
group.Mutex = &sync.Mutex{}
return &group
}
// Choose 选择一个正在准备的vps节点
func (group *DIPGroup) Choose(addr string) {
now := time.Now().Unix()
for ip, dhost := range group.Ready {
@ -81,6 +84,7 @@ func (group *DIPGroup) Choose(addr string) {
}
}
group.Waitor[ip] = group.Ready[ip]
delete(group.Ready, ip)
break
@ -99,8 +103,8 @@ func NewDHost(host string) *DHost {
return &dh
}
func (dh *DHost) OverTime(now int64) int64 {
if now-dh.ActiveTime >= 150 {
func (dh *DHost) OverTime(now int64, limit int64) int64 {
if now-dh.ActiveTime >= limit {
return now - dh.ActiveTime
}
return 0

View File

@ -92,6 +92,14 @@ func (swi *Switch) checkInReady(ip string, now int64) {
dipg.Group[ip].ActiveTime = now
if dh, ok := dipg.Waitor[ip]; ok {
if dh.OverTime(now, 20) > 0 {
delete(dipg.Waitor, ip)
} else {
return
}
}
if dipg.Current == nil {
dhost := NewDHost(ip)
dhost.ActiveTime = now
@ -161,7 +169,7 @@ func (swi *Switch) switchActives(w http.ResponseWriter, req *http.Request) {
isappend := int64(1)
for _, dhost := range group.Group {
isappend *= dhost.OverTime(now)
isappend *= dhost.OverTime(now, 150)
}
if isappend == 0 {
content = append(content, addr)