feat: implement time wheel for scheduling tasks and refactor bond and steam playing checks to use new task scheduling utility

This commit is contained in:
lixiangwuxian
2025-01-10 01:27:50 +08:00
parent fa635ad9f1
commit 8dcef53924
3 changed files with 197 additions and 12 deletions

View File

@@ -11,6 +11,7 @@ import (
"git.lxtend.com/qqbot/action"
"git.lxtend.com/qqbot/model"
"git.lxtend.com/qqbot/sqlite3"
"git.lxtend.com/qqbot/util"
)
func init() {
@@ -131,25 +132,22 @@ func RoundCheckNewBond() {
time.Sleep(5 * time.Second)
}
// once := true
for {
// if !once {
time.Sleep(5 * time.Minute)
// }
util.AddCycleTask("checkNewBond", 5*time.Minute, 5*time.Minute, func() {
bonds, err := GetBondsData()
if bonds == nil || err != nil {
fmt.Println("Error getting bonds data:", err)
continue
return
}
groups, err := GetGroupListens()
if err != nil {
fmt.Println("Error getting group listens:", err)
continue
return
}
for _, bond := range bonds {
exists, err := BondDataExists(bond.SecurityCode)
if err != nil {
fmt.Println("Error checking bond data exists:", err)
continue
return
}
if !exists {
for _, group := range groups {
@@ -167,6 +165,5 @@ func RoundCheckNewBond() {
}
AddBondData(bond)
}
// once = false
}
})
}