You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.0 KiB
103 lines
2.0 KiB
2 years ago
|
package biz
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
v1 "git.gz.internal.jumaiyx.cn/jm/jmproto/room/v1"
|
||
|
"git.gz.internal.jumaiyx.cn/job/room-server-clear/internal/util"
|
||
|
"git.gz.internal.jumaiyx.cn/job/room-server-clear/pkg/room"
|
||
|
k8s_client "git.gz.internal.jumaiyx.cn/pkg/k8s-client"
|
||
|
"git.gz.internal.jumaiyx.cn/pkg/log"
|
||
|
"github.com/google/wire"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// ProviderBizSet is biz providers.
|
||
|
var ProviderBizSet = wire.NewSet(NewBiz)
|
||
|
|
||
|
type Biz struct {
|
||
|
log log.Logger
|
||
|
room *room.RoomService
|
||
|
podChan chan PodName
|
||
|
}
|
||
|
|
||
|
func NewBiz(logger log.Logger, room *room.RoomService) *Biz {
|
||
|
return &Biz{
|
||
|
log: logger,
|
||
|
podChan: make(chan PodName, 2),
|
||
|
room: room,
|
||
|
//data: data,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (biz *Biz) Check() {
|
||
|
|
||
|
}
|
||
|
|
||
|
type PodName struct {
|
||
|
RoomId int64
|
||
|
BranchId int64
|
||
|
Name string
|
||
|
}
|
||
|
|
||
|
func (biz *Biz) pods(ctx context.Context) {
|
||
|
pod, err := k8s_client.NewPod(k8s_client.UnityNamespace, biz.log)
|
||
|
if err != nil {
|
||
|
biz.log.Errorf("New pod failed:%v", err)
|
||
|
return
|
||
|
}
|
||
|
pods, err := pod.All(ctx, 0)
|
||
|
if err != nil {
|
||
|
biz.log.Errorf("Get pod list failed:%v", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
for _, v := range pods {
|
||
|
name := v.Name[18:]
|
||
|
names := strings.Split(name, "-")
|
||
|
roomId := util.StringTarnsInt64(names[0])
|
||
|
if roomId > 0 {
|
||
|
biz.podChan <- PodName{
|
||
|
RoomId: roomId,
|
||
|
BranchId: util.StringTarnsInt64(names[1]),
|
||
|
Name: v.Name,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//time.Sleep(time.Second * 1)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (biz *Biz) getRoom(ctx context.Context) {
|
||
|
for {
|
||
|
select {
|
||
|
case pod := <-biz.podChan:
|
||
|
r, err := biz.room.GetRoom(ctx, &v1.GetRoomRequest{
|
||
|
RoomId: pod.RoomId,
|
||
|
})
|
||
|
if err != nil {
|
||
|
biz.log.Errorf("Get room failed:%v", err)
|
||
|
continue
|
||
|
}
|
||
|
// 删除
|
||
|
if r.RoomId == 0 || r.Status != 1 {
|
||
|
fmt.Println(r)
|
||
|
fmt.Println(r.RoomId, r.Status)
|
||
|
continue
|
||
|
}
|
||
|
var flag bool
|
||
|
for _, branch := range r.Branches {
|
||
|
fmt.Println(branch)
|
||
|
if branch.BranchId == pod.BranchId {
|
||
|
flag = true
|
||
|
}
|
||
|
}
|
||
|
fmt.Println(flag)
|
||
|
case <-time.After(10 * time.Second):
|
||
|
biz.log.Info("ok")
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|