insert cron

This commit is contained in:
shoopea 2019-12-12 17:42:05 +08:00
parent b9c2ab7c9f
commit a58ae1d571
2 changed files with 34 additions and 0 deletions

29
cron.go Normal file
View File

@ -0,0 +1,29 @@
package main
import (
"github.com/robfig/cron/v3"
//"gopkg.in/robfig/cron.v3"
)
func startCron() *Cron {
c := cron.New(cron.WithLocation(time.UTC))
c.AddFunc("@every 1m", cronSendReport)
c.Start()
return
}
func stopCron(c *Cron) {
c.Stop()
return
}
func cronSendReport() {
muxClients.RLock()
for id, c := range clients {
if c.Active {
clientSendCWMsg(c.TGUserID64, `/report`)
}
}
muxClients.RUnlock()
return
}

View File

@ -9,6 +9,7 @@ import (
"sync"
"time"
"github.com/robfig/cron/v3"
"gopkg.in/gcfg.v1"
_ "github.com/go-sql-driver/mysql"
@ -50,6 +51,8 @@ var (
db *sql.DB
b *tb.Bot
c *cron.Cron
cfg Config
RndSrc *rand.Rand
@ -154,6 +157,8 @@ func main() {
}
b.Send(&u, "Bot restarted")
c = startCron()
MQCWMsgQueue = make(chan ChatWarsMessage, MQCWMsgQueueSize)
SQLMsgIdentifyQueue = make(chan int64, SQLMsgIdentifyQueueSize)
TGCmdQueue = make(chan TGCommand, TGCmdQueueSize)