chore: remove scheduler

This commit is contained in:
juancwu 2026-04-06 15:22:21 +00:00
commit c87e1c309e
2 changed files with 0 additions and 62 deletions

View file

@ -13,7 +13,6 @@ import (
"git.juancwu.dev/juancwu/budgit/internal/app"
"git.juancwu.dev/juancwu/budgit/internal/config"
"git.juancwu.dev/juancwu/budgit/internal/routes"
"git.juancwu.dev/juancwu/budgit/internal/scheduler"
)
// version is set at build time via -ldflags.
@ -36,12 +35,6 @@ func main() {
handler := routes.SetupRoutes(a)
// Start recurring expense scheduler
schedulerCtx, schedulerCancel := context.WithCancel(context.Background())
defer schedulerCancel()
sched := scheduler.New(a.RecurringExpenseService, a.RecurringReceiptService)
go sched.Start(schedulerCtx)
// Health check bypasses all middleware
finalHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet && r.URL.Path == "/healthz" {

View file

@ -1,55 +0,0 @@
package scheduler
import (
"context"
"log/slog"
"time"
"git.juancwu.dev/juancwu/budgit/internal/service"
)
type Scheduler struct {
recurringService *service.RecurringExpenseService
recurringReceiptService *service.RecurringReceiptService
interval time.Duration
}
func New(recurringService *service.RecurringExpenseService, recurringReceiptService *service.RecurringReceiptService) *Scheduler {
return &Scheduler{
recurringService: recurringService,
recurringReceiptService: recurringReceiptService,
interval: 1 * time.Hour,
}
}
func (s *Scheduler) Start(ctx context.Context) {
// Run immediately on startup to catch up missed recurrences
s.run()
ticker := time.NewTicker(s.interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
slog.Info("scheduler stopping")
return
case <-ticker.C:
s.run()
}
}
}
func (s *Scheduler) run() {
now := time.Now()
slog.Info("scheduler: processing due recurring expenses")
if err := s.recurringService.ProcessDueRecurrences(now); err != nil {
slog.Error("scheduler: failed to process recurring expenses", "error", err)
}
slog.Info("scheduler: processing due recurring receipts")
if err := s.recurringReceiptService.ProcessDueRecurrences(now); err != nil {
slog.Error("scheduler: failed to process recurring receipts", "error", err)
}
}