From: qydysky Date: Wed, 3 Feb 2021 12:29:08 +0000 (+0800) Subject: 防止多余小心心获取进程 X-Git-Tag: v0.5.7~1^2~14 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=5115b56d77929f34525b4f2f25258c0fd74f9479;p=bili_danmu%2F.git 防止多余小心心获取进程 --- diff --git a/CV/Var.go b/CV/Var.go index 71b7e44..193daa0 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -2,6 +2,7 @@ package cv import ( "time" + tmplKV "github.com/qydysky/part/tmplKV" mq "github.com/qydysky/part/msgq" s "github.com/qydysky/part/buf" log "github.com/qydysky/part/log" @@ -33,6 +34,10 @@ type Danmu_Main_mq_item struct { //200长度防止push击穿 var Danmu_Main_mq = mq.New(200) +//调用记录 +var Bootmap = tmplKV.New_tmplK(50,60*60) +//1h中允许50个不同key(函数设置字段)-id(对应对话id) + //日志 var Log = log.New(log.Config{ File:`danmu.log`, diff --git a/F/api.go b/F/api.go index f1a2d91..93ba79b 100644 --- a/F/api.go +++ b/F/api.go @@ -1104,6 +1104,7 @@ func (i *api) F_x25Kn() (o *api) { if o.Parent_area_id == -1 {apilog.L(`E: `,`失败!未获取Parent_area_id`);return} if o.Area_id == -1 {apilog.L(`E: `,`失败!未获取Area_id`);return} if api_limit.TO() {apilog.L(`E: `,`超时!`);return}//超额请求阻塞,超时将取消 + func_id := c.Bootmap.Set(`api.F_x25Kn`)//获取函数调用会话id {//查看今天小心心数量 var num = 0 @@ -1116,6 +1117,7 @@ func (i *api) F_x25Kn() (o *api) { apilog.L(`I: `,`今天小心心已满!`);return } else { apilog.L(`I: `,`今天已有`,num,`个小心心,开始获取`) + defer apilog.L(`T: `,`退出`) } } @@ -1141,6 +1143,7 @@ func (i *api) F_x25Kn() (o *api) { } {//初始化 + if !c.Bootmap.Check(`api.F_x25Kn`, func_id) {apilog.L(`I: `,`多余退出`);return}//有新会话产生,旧的退出 PostStr := `id=[`+strconv.Itoa(o.Parent_area_id)+`,`+strconv.Itoa(o.Area_id)+`,`+strconv.Itoa(loop_num)+`,`+strconv.Itoa(o.Roomid)+`]&` PostStr += `device=["`+LIVE_BUVID+`","`+new_uuid+`"]&` PostStr += `ts=`+strconv.Itoa(int(p.Sys().GetMTime())) @@ -1187,23 +1190,9 @@ func (i *api) F_x25Kn() (o *api) { } {//loop - var cancle = make(chan struct{},1) - //使用带tag的消息队列在功能间传递消息 - c.Danmu_Main_mq.Pull_tag(map[string]func(interface{})(bool){ - `change_room`:func(data interface{})(bool){//换房时退出当前房间 - close(cancle) - return true - }, - }) - - defer apilog.L(`I: `,`退出`) - for loop_num < 24*5 { - select{ - case <- time.After(time.Second*time.Duration(res.Data.Heartbeat_interval)): - case <- cancle: - return - } + <- time.After(time.Second*time.Duration(res.Data.Heartbeat_interval)) + if !c.Bootmap.Check(`api.F_x25Kn`, func_id) {apilog.L(`I: `,`多余退出`);return}//有新会话产生,旧的退出 loop_num += 1 diff --git a/demo/go.mod b/demo/go.mod index 3c450b0..aff91e2 100644 --- a/demo/go.mod +++ b/demo/go.mod @@ -11,7 +11,7 @@ require ( github.com/miekg/dns v1.1.38 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/qydysky/bili_danmu v0.5.7 - github.com/qydysky/part v0.3.10 // indirect + github.com/qydysky/part v0.3.11 // indirect github.com/shirou/gopsutil v3.21.1+incompatible // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect diff --git a/demo/go.sum b/demo/go.sum index 98d1a47..58ce092 100644 --- a/demo/go.sum +++ b/demo/go.sum @@ -131,6 +131,8 @@ github.com/qydysky/part v0.3.9 h1:eX/n+839mwX5vRDHtmO3jU0eIQJynE8wmEqCZN7xMZM= github.com/qydysky/part v0.3.9/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part v0.3.10 h1:hb6HcedujeqfKWmV1r30Wu9JYcajS0cM4bLFco63bIY= github.com/qydysky/part v0.3.10/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= +github.com/qydysky/part v0.3.11 h1:GNNgS4lNWi2iw8E9HYKgje4+w0uwTb2+2XkKxAnFnjM= +github.com/qydysky/part v0.3.11/go.mod h1:43opuciW71sZvOR67kye50jgMDSDrn/t6+LefNdlXPg= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad h1:Jtzf509lQrkUMGTV0Sc6IDCAiR1VrBcHrIban7hpye4= github.com/qydysky/part/msgq v0.0.0-20201213031129-ca3253dc72ad/go.mod h1:w32TkJNVtTJd4LOS09cq+4uYG6itcN2vsqw+slp44Rg= github.com/qydysky/part/msgq v0.0.0-20201213120821-f36e49c32bba h1:1ew9dRpc0Rux0WkWeT/4AE15ynYWmL2D7onJEJIFOB8=