chirpnest/cron.go

32 lines
454 B
Go
Raw Normal View History

2019-12-12 10:42:05 +01:00
package main
import (
2019-12-12 10:45:27 +01:00
"time"
2019-12-12 10:44:18 +01:00
//"github.com/robfig/cron/v3"
"gopkg.in/robfig/cron.v3"
2019-12-12 10:42:05 +01:00
)
2019-12-12 10:45:27 +01:00
func startCron() *cron.Cron {
2019-12-12 10:42:05 +01:00
c := cron.New(cron.WithLocation(time.UTC))
c.AddFunc("@every 1m", cronSendReport)
c.Start()
2019-12-12 10:49:18 +01:00
return c
2019-12-12 10:42:05 +01:00
}
2019-12-12 10:45:27 +01:00
func stopCron(c *cron.Cron) {
2019-12-12 10:42:05 +01:00
c.Stop()
return
}
func cronSendReport() {
muxClients.RLock()
2019-12-12 10:51:01 +01:00
for _, c := range clients {
2019-12-12 10:42:05 +01:00
if c.Active {
clientSendCWMsg(c.TGUserID64, `/report`)
}
}
muxClients.RUnlock()
return
}