Refactored project structure

This commit is contained in:
2025-10-16 22:45:31 +02:00
parent cf74cce51c
commit d13ea9fc27
13 changed files with 1156 additions and 1023 deletions

View File

@@ -0,0 +1,46 @@
package handlers
import (
"log/slog"
"strconv"
"strings"
"time"
)
func StartDailyCleanup(app *App) {
loc, _ := time.LoadLocation("Europe/Budapest")
go func() {
for {
// read finalize_time from DB (default "10:30")
t := app.getSetting("finalize_time", "10:30")
// parse "HH:MM"
parts := strings.Split(t, ":")
hour, _ := strconv.Atoi(parts[0])
minute, _ := strconv.Atoi(parts[1])
now := time.Now().In(loc)
next := time.Date(now.Year(), now.Month(), now.Day(), hour, minute, 0, 0, loc)
if !next.After(now) {
next = next.Add(24 * time.Hour)
}
slog.Info("Next finalize scheduled", "time", next)
timer := time.NewTimer(time.Until(next))
select {
case <-timer.C:
if err := finalizeOrders(app); err != nil {
slog.Error("Daily finalize failed", "error", err)
} else {
slog.Info("Orders finalized", "time", time.Now().In(loc))
}
case <-app.FinalizeUpdate:
slog.Info("Finalize time updated, recalculating...")
timer.Stop()
}
}
}()
}