feat: add cron

This commit is contained in:
Максим Слипенко 2024-12-13 14:04:27 +03:00
parent 26c751ccb7
commit f2ef06ca81

View file

@ -3,6 +3,7 @@ package router
import ( import (
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware" "github.com/go-chi/chi/v5/middleware"
"github.com/go-co-op/gocron/v2"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/app" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/app"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
@ -32,6 +33,21 @@ func (r *Router) Setup() *chi.Mux {
repoService := reposervice.New(r.app) repoService := reposervice.New(r.app)
repoService.ForceUpdate() repoService.ForceUpdate()
s, _ := gocron.NewScheduler()
defer func() { _ = s.Shutdown() }()
_, _ = s.NewJob(
gocron.CronJob(
"0 4 * * *",
false,
),
gocron.NewTask(
func() {
repoService.ForceUpdate()
},
),
)
taskController := taskcontroller.New( taskController := taskcontroller.New(
r.app, r.app,
taskService, taskService,