diff --git a/Dockerfile b/Dockerfile index 0e2f0ff..8b1f413 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ COPY . . RUN go build -o aides-repo-api ./cmd/aides-repo-api/main.go # Второй этап: создание финального образа -FROM registry.altlinux.org/alt/alt:sisyphus +FROM registry.altlinux.org/sisyphus/alt:20241211 RUN \ apt-get update && \ diff --git a/internal/app/app.go b/internal/app/app.go index 374b10d..08f3f66 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -6,6 +6,7 @@ import ( "gorm.io/driver/postgres" "gorm.io/gorm" + gormlogger "gorm.io/gorm/logger" "moul.io/zapgorm2" "code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config" @@ -52,6 +53,7 @@ func (app *App) createLogger() { func (app *App) createDb() { logger := zapgorm2.New(app.logger.GetZap()) + logger.LogMode(gormlogger.Info) logger.SetAsDefault() dsn := fmt.Sprintf( "host=%s port=%s user=%s password=%s dbname=%s sslmode=disable", diff --git a/internal/services/cronservice/service.go b/internal/services/cronservice/service.go index 55bc5bd..02e8f7d 100644 --- a/internal/services/cronservice/service.go +++ b/internal/services/cronservice/service.go @@ -2,7 +2,6 @@ package cronservice import ( "log" - "time" "github.com/go-co-op/gocron/v2" @@ -20,7 +19,7 @@ type Service struct { } func New(repo RepoService) *Service { - scheduler, err := gocron.NewScheduler(gocron.WithLocation(time.UTC)) + scheduler, err := gocron.NewScheduler() if err != nil { log.Fatalf("Не удалось создать планировщик: %v", err) } @@ -33,11 +32,11 @@ func New(repo RepoService) *Service { func (s *Service) SetupCronJobs() { _, err := s.scheduler.NewJob( - gocron.CronJob("* * * * *", false), + gocron.CronJob("0 4 * * *", false), gocron.NewTask(func() { log := logger.GetLogger() log.Info( - "Cron run!", + "[cron] force update is started", ) s.repoService.ForceUpdate() }), diff --git a/internal/services/reposervice/service.go b/internal/services/reposervice/service.go index e4ea7f6..856d071 100644 --- a/internal/services/reposervice/service.go +++ b/internal/services/reposervice/service.go @@ -53,8 +53,8 @@ func runGenbasedir(repoDir, arch, repoName string) { arch, repoName, ) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + cmd.Stdout = nil + cmd.Stderr = nil err := cmd.Run() if err != nil { log.Error( @@ -106,7 +106,7 @@ func (s *Service) ForceUpdate() { Where(&altRepo). First(&altRepo) - s.db.Debug(). + s.db. Model(&models.GitRepoAltRepoTask{}). Select("tasks.*"). Joins("JOIN tasks ON tasks.id = git_repo_alt_repo_tasks.last_task_id"). @@ -158,7 +158,7 @@ func (s *Service) ForceUpdate() { runGenbasedir(repoPath, arch, repoName) } - s.db.Debug(). + s.db. Model(&models.GitRepoAltRepoTask{}). Where(&models.GitRepoAltRepoTask{ ALTRepoID: altRepo.ID, diff --git a/internal/services/taskservice/create.go b/internal/services/taskservice/create.go index e0b9e70..91d8cef 100644 --- a/internal/services/taskservice/create.go +++ b/internal/services/taskservice/create.go @@ -8,7 +8,7 @@ func (s *Service) Create(repo string) (*models.Task, error) { taskRepo := models.GitRepo{ Name: repo, } - s.db.Debug(). + s.db. Where(&taskRepo). FirstOrCreate(&taskRepo) diff --git a/internal/services/taskservice/service.go b/internal/services/taskservice/service.go index a2e2f1e..1e1bf69 100644 --- a/internal/services/taskservice/service.go +++ b/internal/services/taskservice/service.go @@ -35,7 +35,7 @@ func (s *Service) onTaskComplete(task *models.Task) error { ALTRepoID: 1, RepoID: task.RepoID, } - s.db.Debug(). + s.db. Where(&grart). FirstOrCreate(&grart) @@ -61,7 +61,6 @@ func (s *Service) tasksCleanup(r *models.GitRepoAltRepoTask, n int) { var lastNTaskIDs []uint s.db. - Debug(). Table("tasks"). Select("id"). Where("repo_id = ?", r.ID). @@ -75,7 +74,6 @@ func (s *Service) tasksCleanup(r *models.GitRepoAltRepoTask, n int) { var taskIDsToDelete []int s.db. - Debug(). Model(&models.Task{}). Select("id"). Where("repo_id = ?", r.RepoID). @@ -85,7 +83,6 @@ func (s *Service) tasksCleanup(r *models.GitRepoAltRepoTask, n int) { if len(taskIDsToDelete) > 0 { s.db. - Debug(). Model(&models.Task{}). Where("id IN ?", taskIDsToDelete). Update("files_removed", true)