]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Improve api校验失败重试
authorqydysky <qydysky@foxmail.com>
Sun, 31 Mar 2024 14:37:46 +0000 (22:37 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 31 Mar 2024 14:37:46 +0000 (22:37 +0800)
F/api.go
go.mod
go.sum

index 6129bd5247bc8b6c0aa4dfda09051787cc5e7a98..ad8d711a3ac8802e9b51a344db6913731c356a39 100644 (file)
--- a/F/api.go
+++ b/F/api.go
@@ -11,6 +11,7 @@ import (
        "strconv"
        "strings"
        "sync"
+       "sync/atomic"
        "time"
 
        c "github.com/qydysky/bili_danmu/CV"
@@ -35,7 +36,8 @@ var api_limit = limit.New(2, "1s", "30s") //频率限制2次/s,最大等待时
 
 type GetFunc struct {
        *c.Common
-       l sync.RWMutex
+       count atomic.Int32
+       l     sync.RWMutex
 }
 
 type cacheItem struct {
@@ -50,6 +52,14 @@ func Get(c *c.Common) *GetFunc {
 func (c *GetFunc) Get(key string) {
        apilog := apilog.Base_add(`Get`)
 
+       current := c.count.Add(1)
+       defer c.count.Add(-1)
+
+       if current > 10 {
+               apilog.L(`E: `, `max loop`)
+               return
+       }
+
        if api_limit.TO() {
                return
        } //超额请求阻塞,超时将取消
@@ -219,7 +229,9 @@ func (c *GetFunc) Get(key string) {
                }
        )
 
-       if fList, ok := api_can_get[key]; ok {
+       if fList, ok := api_can_get[key]; !ok {
+               apilog.L(`E: `, `no api`, key)
+       } else {
                for _, fItem := range fList {
                        apilog.Log_show_control(false).L(`T: `, `Get`, key)
 
@@ -254,13 +266,17 @@ func (c *GetFunc) Get(key string) {
                                        continue
                                }
                        }
+
                        if checkf, ok := check[key]; ok {
                                c.l.RLock()
                                if checkf() {
                                        c.l.RUnlock()
                                        break
+                               } else {
+                                       c.l.RUnlock()
+                                       apilog.L(`W: `, `check fail`, key)
+                                       c.Get(key)
                                }
-                               c.l.RUnlock()
                        }
                }
        }
diff --git a/go.mod b/go.mod
index 474fa23495e978d50b877483b4f7fde880868e05..1edf956e69ab7e603f8d9a452b1e6ae398d624f2 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.22
 require (
        github.com/gotk3/gotk3 v0.6.3
        github.com/mdp/qrterminal/v3 v3.2.0
-       github.com/qydysky/part v0.28.20240325172911
+       github.com/qydysky/part v0.28.20240331120148
        github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
        golang.org/x/text v0.14.0
diff --git a/go.sum b/go.sum
index 032bbbe3614f013d0210ba68ee5f4b957a6ff25d..65dc13e3f94b7ac7e9a0e7cb7ac31e6858b02faf 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -37,8 +37,8 @@ github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdh
 github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/qydysky/part v0.28.20240325172911 h1:2wu7BIpfsxvoXYZjzd79NQCU4B4ZY61Iu97NwxvupRQ=
-github.com/qydysky/part v0.28.20240325172911/go.mod h1:XytV5dI1Y7+qvjhsa2TMvi55RBZQQf0LCDYQ1kUCYqM=
+github.com/qydysky/part v0.28.20240331120148 h1:LiZsVm+U50+Lf+L6b+MaGZcytoQCnWVWZ35axOeyebs=
+github.com/qydysky/part v0.28.20240331120148/go.mod h1:XytV5dI1Y7+qvjhsa2TMvi55RBZQQf0LCDYQ1kUCYqM=
 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
 github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=