From 2f061f8bcd58ca1eca577561479ad81ce50f0e95 Mon Sep 17 00:00:00 2001 From: furu04 Date: Wed, 22 Apr 2026 23:45:01 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B9=B0=E3=82=8A=E8=BF=94=E3=81=97=E8=AA=B2?= =?UTF-8?q?=E9=A1=8C=E3=82=B9=E3=82=B1=E3=82=B8=E3=83=A5=E3=83=BC=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=81=A8GenerationLeadDays=E3=83=95=E3=82=A3=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/main.go | 27 +++++++++++++++++++------ internal/models/recurring_assignment.go | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 9b24a0f..7e20ffc 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,35 +3,50 @@ package main import ( "flag" "log" + "time" "homework-manager/internal/config" "homework-manager/internal/database" "homework-manager/internal/router" + "homework-manager/internal/service" ) func main() { - // Parse command line flags configPath := flag.String("config", "", "Path to config.ini file (default: config.ini in current directory)") flag.Parse() - // Load configuration cfg := config.Load(*configPath) - // Connect to database log.Printf("Connecting to database (driver: %s)", cfg.Database.Driver) if err := database.Connect(cfg.Database, cfg.Debug); err != nil { log.Fatalf("Failed to connect to database: %v", err) } - // Run migrations if err := database.Migrate(); err != nil { log.Fatalf("Failed to run migrations: %v", err) } - // Setup router + recurringService := service.NewRecurringAssignmentService() + if err := recurringService.GenerateNextAssignments(); err != nil { + log.Printf("recurring generation error on startup: %v", err) + } + go func() { + defer func() { + if r := recover(); r != nil { + log.Printf("recurring scheduler panic: %v", r) + } + }() + ticker := time.NewTicker(15 * time.Minute) + defer ticker.Stop() + for range ticker.C { + if err := recurringService.GenerateNextAssignments(); err != nil { + log.Printf("recurring generation error: %v", err) + } + } + }() + r := router.Setup(cfg) - // Start server log.Printf("Server starting on http://localhost:%s", cfg.Port) if err := r.Run(":" + cfg.Port); err != nil { log.Fatalf("Failed to start server: %v", err) diff --git a/internal/models/recurring_assignment.go b/internal/models/recurring_assignment.go index b24599a..a5120f2 100644 --- a/internal/models/recurring_assignment.go +++ b/internal/models/recurring_assignment.go @@ -45,6 +45,8 @@ type RecurringAssignment struct { GeneratedCount int `gorm:"default:0" json:"generated_count"` EditBehavior string `gorm:"not null;default:this_only" json:"edit_behavior"` + GenerationLeadDays int `gorm:"default:0" json:"generation_lead_days"` + GenerationLeadTime string `gorm:"default:''" json:"generation_lead_time"` ReminderEnabled bool `gorm:"default:false" json:"reminder_enabled"` ReminderOffset *int `json:"reminder_offset,omitempty"` UrgentReminderEnabled bool `gorm:"default:true" json:"urgent_reminder_enabled"`