add waitor
This commit is contained in:
parent
4d50b03400
commit
da98287e2e
8
dip.go
8
dip.go
|
@ -45,6 +45,7 @@ func (worker *DIPWorker) ShowGroupInfo() string {
|
||||||
|
|
||||||
type DIPGroup struct {
|
type DIPGroup struct {
|
||||||
Group map[string]*DHost // 原始参照
|
Group map[string]*DHost // 原始参照
|
||||||
|
Waitor map[string]*DHost
|
||||||
Ready map[string]*DHost
|
Ready map[string]*DHost
|
||||||
IPTableNum string
|
IPTableNum string
|
||||||
Current *DHost
|
Current *DHost
|
||||||
|
@ -55,11 +56,13 @@ type DIPGroup struct {
|
||||||
func NewDIPGroup() *DIPGroup {
|
func NewDIPGroup() *DIPGroup {
|
||||||
group := DIPGroup{}
|
group := DIPGroup{}
|
||||||
group.Group = make(map[string]*DHost)
|
group.Group = make(map[string]*DHost)
|
||||||
|
group.Waitor = make(map[string]*DHost)
|
||||||
group.Ready = make(map[string]*DHost)
|
group.Ready = make(map[string]*DHost)
|
||||||
group.Mutex = &sync.Mutex{}
|
group.Mutex = &sync.Mutex{}
|
||||||
return &group
|
return &group
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Choose 选择一个正在准备的vps节点
|
||||||
func (group *DIPGroup) Choose(addr string) {
|
func (group *DIPGroup) Choose(addr string) {
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
for ip, dhost := range group.Ready {
|
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)
|
delete(group.Ready, ip)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
@ -99,8 +103,8 @@ func NewDHost(host string) *DHost {
|
||||||
return &dh
|
return &dh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dh *DHost) OverTime(now int64) int64 {
|
func (dh *DHost) OverTime(now int64, limit int64) int64 {
|
||||||
if now-dh.ActiveTime >= 150 {
|
if now-dh.ActiveTime >= limit {
|
||||||
return now - dh.ActiveTime
|
return now - dh.ActiveTime
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
|
10
switch.go
10
switch.go
|
@ -92,6 +92,14 @@ func (swi *Switch) checkInReady(ip string, now int64) {
|
||||||
|
|
||||||
dipg.Group[ip].ActiveTime = now
|
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 {
|
if dipg.Current == nil {
|
||||||
dhost := NewDHost(ip)
|
dhost := NewDHost(ip)
|
||||||
dhost.ActiveTime = now
|
dhost.ActiveTime = now
|
||||||
|
@ -161,7 +169,7 @@ func (swi *Switch) switchActives(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
isappend := int64(1)
|
isappend := int64(1)
|
||||||
for _, dhost := range group.Group {
|
for _, dhost := range group.Group {
|
||||||
isappend *= dhost.OverTime(now)
|
isappend *= dhost.OverTime(now, 150)
|
||||||
}
|
}
|
||||||
if isappend == 0 {
|
if isappend == 0 {
|
||||||
content = append(content, addr)
|
content = append(content, addr)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user