insert cron
This commit is contained in:
parent
b9c2ab7c9f
commit
a58ae1d571
29
cron.go
Normal file
29
cron.go
Normal 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
|
||||
}
|
5
main.go
5
main.go
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user