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:
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -176,11 +176,11 @@ func checkSteamPlaying(msg model.Message) model.Reply {
|
||||
func RoundCheckSteamPlaying() {
|
||||
once := true
|
||||
playingMap := map[int64]map[string]string{}
|
||||
for {
|
||||
util.AddCycleTask("checkSteamPlaying", 15*time.Second, 15*time.Second, func() {
|
||||
groups, err := getAllGroupID()
|
||||
if err != nil {
|
||||
fmt.Println("获取群列表失败: ", err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
|
||||
for _, group := range groups {
|
||||
@@ -212,5 +212,5 @@ func RoundCheckSteamPlaying() {
|
||||
}
|
||||
}
|
||||
once = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user