From 6be72fb3c610e5e13d4f2a95959945091b8e0e17 Mon Sep 17 00:00:00 2001 From: Vlad Rud Date: Fri, 4 Feb 2022 12:39:57 +0300 Subject: [PATCH] added task scheduler --- kicker/tasks.go | 2 +- main.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kicker/tasks.go b/kicker/tasks.go index f6e4937..5792a3b 100644 --- a/kicker/tasks.go +++ b/kicker/tasks.go @@ -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() diff --git a/main.go b/main.go index 48cb09d..38121e1 100644 --- a/main.go +++ b/main.go @@ -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() }