added task scheduler

This commit is contained in:
Vlad Rud 2022-02-04 12:39:57 +03:00
parent 64fb51aa0c
commit 6be72fb3c6
2 changed files with 7 additions and 1 deletions

View File

@ -11,7 +11,7 @@ import (
tb "gopkg.in/tucnak/telebot.v3"
)
func KickOldUsers(b tb.Bot) {
func TaskKickOldUsers(b tb.Bot) {
d := db.GetDatabase()
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()

View File

@ -6,7 +6,9 @@ import (
"kickerbot/kicker"
"log"
"os"
"time"
"github.com/go-co-op/gocron"
"github.com/joho/godotenv"
)
@ -29,4 +31,8 @@ func main() {
Bot.Init()
Bot.AddHandlers(kicker.HandlersV1)
Bot.Bot.Start()
scheduler := gocron.NewScheduler(time.UTC)
scheduler.Every(1).Minutes().Do(func() { kicker.TaskKickOldUsers(*Bot.Bot) })
scheduler.StartAsync()
}